Skip to content

🐛 Bug Report: New functions are not created with the new structure 1.4.2. #6186

Description

@Kriihz77

👟 Reproduction steps

Through the CLI, a function was created in Python 3.10, and it created the old structure of the functions and not the new one proposed for version 1.4.x.

👍 Expected behavior

fromappwrite.clientimportClientimportos# This is your Appwrite function# It's executed each time we get a requestdefmain(context):
# Why not try the Appwrite SDK?## client = (# Client()# .set_endpoint("https://cloud.appwrite.io/v1")# .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])# .set_key(os.environ["APPWRITE_API_KEY"])# )# You can log messages to the consolecontext.log("Hello, Logs!")
# If something goes wrong, log an errorcontext.error("Hello, Errors!")
# The `context.req` object contains the request dataifcontext.req.method=="GET":
# Send a response with the res object helpers# `context.res.send()` dispatches a string back to the clientreturncontext.res.send("Hello, World!")
# `context.res.json()` is a handy helper for sending JSONreturncontext.res.json({
"motto": "Build Fast. Scale Big. All in One Place.",
"learn": "https://appwrite.io/docs",
"connect": "https://appwrite.io/discord",
"getInspired": "https://builtwith.appwrite.io",
})

👎 Actual Behavior

fromappwrite.clientimportClient# You can remove imports of services you don't usefromappwrite.services.accountimportAccountfromappwrite.services.avatarsimportAvatarsfromappwrite.services.databasesimportDatabasesfromappwrite.services.functionsimportFunctionsfromappwrite.services.healthimportHealthfromappwrite.services.localeimportLocalefromappwrite.services.storageimportStoragefromappwrite.services.teamsimportTeamsfromappwrite.services.usersimportUsers""" 'req' variable has: 'headers' - object with request headers 'payload' - request body data as a string 'variables' - object with function variables 'res' variable has: 'send(text, status)' - function to return text response. Status code defaults to 200 'json(obj, status)' - function to return JSON response. Status code defaults to 200 If an error is thrown, a response with code 500 will be returned."""defmain(req, res):
client=Client()
# You can remove services you don't useaccount=Account(client)
avatars=Avatars(client)
database=Databases(client)
functions=Functions(client)
health=Health(client)
locale=Locale(client)
storage=Storage(client)
teams=Teams(client)
users=Users(client)
ifnotreq.variables.get('APPWRITE_FUNCTION_ENDPOINT') ornotreq.variables.get('APPWRITE_FUNCTION_API_KEY'):
print('Environment variables are not set. Function cannot use Appwrite SDK.')
else:
(
client
.set_endpoint(req.variables.get('APPWRITE_FUNCTION_ENDPOINT', None))
.set_project(req.variables.get('APPWRITE_FUNCTION_PROJECT_ID', None))
.set_key(req.variables.get('APPWRITE_FUNCTION_API_KEY', None))
.set_self_signed(True)
)
returnres.json({
"areDevelopersAwesome": True,
})

additional, an error is being generated when consuming the import

Traceback (most recent call last):
File "/usr/local/server/src/server.py", line 165, in handler
output = await asyncio.wait_for(execute(context), timeout=safeTimeout)
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
return fut.result()
File "/usr/local/server/src/server.py", line 150, in execute
userModule = importlib.import_module("function." + userPath)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/local/server/src/function/src/index.py", line 1, in <module>
from appwrite.client import Client
ModuleNotFoundError: No module named 'appwrite'

🎲 Appwrite version

Version 1.4.x

💻 Operating system

Linux

🧱 Your Environment

1.4.2 and CLI 3.0.0 Branch Master

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingproduct / functionsFixes and upgrades for the Appwrite Functions.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions