Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: Appwrite Cloud Python 3.9 function module not found in tarball #6051

Closed
2 tasks done
tripolskypetr opened this issue Aug 28, 2023 · 5 comments
Closed
2 tasks done
Assignees
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.

Comments

@tripolskypetr
Copy link

tripolskypetr commented Aug 28, 2023

馃憻 Reproduction steps

I am trying to import repository.py from index.py

tripolskypetr@desktop:/mnt/c/appwrite/functions/paginator$ ls
__pycache__  index.py  main.py  repository.py  requirements.txt
tripolskypetr@desktop:/mnt/c/appwrite/functions/paginator$ cat index.py
import sys

from appwrite.exception import AppwriteException

from repository import get_repository_instance

def main(req, res):

    repository = get_repository_instance()

    try:
        repository.try_init(req)
        repository.read_event(req)
    except AppwriteException as err:
        print(err.message)

    print(repository.documents)

    return res.json({
        "areDevelopersAwesome": True,
    })
tripolskypetr@desktop:/mnt/c/Users/tripolskypetr/Documents/GitHub/appwrite/functions/paginator$ 

It works on a local mock environment

tripolskypetr@desktop:/mnt/c/appwrite/functions/paginator$ cat main.py
import mock

from dotenv import dotenv_values

from index import main

req = mock.Mock()
req.headers = {}
req.payload = ""
req.variables = dict(dotenv_values(".env"))

res = mock.Mock()
res.send = lambda text, status = "" : print(text, status)
res.json = lambda data, status = "" : print(data, status)

main(req, res)

But when I deploy that function to appwrite cloud It fails with ModuleNotFoundError

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'repository'

馃憤 Expected behavior

Looks like python function container bootstrap contains these files

print(os.listdir())
['userlib', '.env', '.dockerignore', 'docker-compose.yml', 'server.py', 'start.sh', 'requirements.txt', 'README.md', '.gitignore', 'build.sh', 'Dockerfile']

If I listdir the userlib folder I will get my actual tarball containment

print(os.listdir("./userlib"))
['requirements.txt', 'main.py', '__pycache__', 'repository.py', 'runtime-env', 'index.py']

Using sys.path.append("userlib") fixed the import problem. That should be done by default in server.py

import sys

sys.path.append('userlib')

from appwrite.exception import AppwriteException

from repository import get_repository_instance

"""
Works well
"""

馃憥 Actual Behavior

  1. Please add sys.path.append("userlib") in server.py to allow code spit between multiple files

  2. Please fix empty logs for module import error in python functions

image

馃幉 Appwrite version

Appwrite Cloud

馃捇 Operating system

Linux

馃П Your Environment

cloud.appwrite.io version 1.1.2

馃憖 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?

@tripolskypetr tripolskypetr added the bug Something isn't working label Aug 28, 2023
@joeyouss joeyouss self-assigned this Aug 29, 2023
@joeyouss joeyouss added the product / functions Fixes and upgrades for the Appwrite Functions. label Aug 29, 2023
@joeyouss
Copy link

Hi @tripolskypetr , just to be sure, for requests, have you used this? https://pypi.org/project/requests/

@joeyouss
Copy link

Also, @tripolskypetr , about the second thing related to error logs, yes, we are aware of it and this should be fixed in 1.4. Adding PR here: #5725

@tripolskypetr
Copy link
Author

Hi @tripolskypetr , just to be sure, for requests, have you used this? https://pypi.org/project/requests/

Nope, just used appwrite sdk for requests

@joeyouss
Copy link

Ok cool, I just confirmed and that is also fixed in 1.4, here is a relevant PR: open-runtimes/open-runtimes#137

@joeyouss
Copy link

Closing this issue following the above comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.
Projects
None yet
Development

No branches or pull requests

2 participants