sdk-for-cli icon indicating copy to clipboard operation
sdk-for-cli copied to clipboard

šŸ› Bug Report: Hot-swapping breaks when function is running locally

Open kamarkiewicz opened this issue 2 years ago • 2 comments

šŸ‘Ÿ Reproduction steps

  1. Create a new Appwrite project with a starter function using python-ml-3.11.
  2. Run it with appwrite run function
  3. Trigger a save action on src/main.py

šŸ‘ Expected behavior

Hot-swapping to work. Workaround is to edit node_modules/appwrite-cli/lib/utils.js#L12 with fs.lstatSync which doesn't follow symlinks.

šŸ‘Ž Actual Behavior

ℹ Info: Starting function using Docker ...
♄ Hint: Function automatically restarts when you edit your code.
Preparing for start ...
āœ“ Success: Visit http://localhost:3000/ to execute your function.
Starting ...
ℹ Info: Hot-swapping function.. Files with change are src/main.py
Error: ENOENT: no such file or directory, stat '/Users/kamar/Projects/appwrite/functions/My Awesome Function/.appwrite/hot-swap/runtime-env/bin/python'
    at Object.statSync (node:fs:1658:25)
    at getAllFiles (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/utils.js:12:16)
    at getAllFiles (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/utils.js:13:27)
    at getAllFiles (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/utils.js:13:27)
    at getAllFiles (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/utils.js:13:27)
    at getAllFiles (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/utils.js:13:27)
    at EventEmitter.<anonymous> (/Users/kamar/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/appwrite-cli/lib/commands/run.js:258:37) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/Users/kamar/Projects/appwrite/functions/My Awesome Function/.appwrite/hot-swap/runtime-env/bin/python'
}
^Cℹ Info: Cleaning up ...
āœ“ Success: Local function successfully stopped.

### šŸŽ² Appwrite version

Appwrite Cloud

### šŸ’» Operating system

MacOS

### 🧱 Your Environment

[email protected]

### šŸ‘€ Have you spent some time to check if this issue has been raised before?

- [x] I checked and didn't find similar issue

### šŸ¢ Have you read the Code of Conduct?

- [x] I have read the [Code of Conduct](https://github.com/appwrite/.github/blob/main/CODE_OF_CONDUCT.md)

kamarkiewicz avatar Nov 23 '24 10:11 kamarkiewicz

I just encountered the same issue while running a Python function locally with Appwrite CLI 6.2.2.

šŸ”„ My Environment:

  • OS: Ubuntu 22.04
  • Appwrite CLI Version: 6.2.2
  • Python Version: 3.12.3
  • Function Runtime: Python 3.12
  • Docker Installed: Yes

šŸž Issue Details:

Whenever I modify my function's code (even a single character), Appwrite detects the change and attempts to hot-swap the function. However, instead of applying the update correctly, it throws the same ENOENT error, failing to locate the Python binary inside .appwrite/hot-swap/runtime-env/bin/python.

āš ļø Error Output:

ℹ Info: Hot-swapping function.. Files with change are src/main.py Error: ENOENT: no such file or directory, stat '/home/atlasdev/projects/tasknotes/functions/Function Sample/.appwrite/hot-swap/runtime-env/bin/python' at Object.statSync (node:fs:1688:3) at getAllFiles (/usr/local/lib/node_modules/appwrite-cli/lib/utils.js:12:16) ...

šŸ” Additional Findings:

I noticed that in .appwrite/hot-swap/runtime-env/bin/, the python, python3, and python3.12 binaries are symbolic links, but they appear to be broken (they don't point to valid files). This seems to be why stat fails when attempting to locate the binary.

Has there been any progress on fixing this in newer versions? If there's anything I can test to help debug, let me know!

Thanks!

TechAtlasDev avatar Mar 23 '25 18:03 TechAtlasDev

@kamarkiewicz @TechAtlasDev thanks for raising the issue! seems like the issue might be isolated to python functions specifically as i just tried a node function and it worked with no issues.

I will begun investigation on this and let you know if a fix is available šŸ‘

ChiragAgg5k avatar Mar 29 '25 06:03 ChiragAgg5k