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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection.py name conflict #85

Open
bullemer opened this issue Feb 1, 2025 · 1 comment · May be fixed by #86
Open

Collection.py name conflict #85

bullemer opened this issue Feb 1, 2025 · 1 comment · May be fixed by #86

Comments

@bullemer
Copy link

bullemer commented Feb 1, 2025

my python fast-api runs locally, but when i deploy it on my server i get: "ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (/home/fastapi-user/ella-brevia/brevia/collections.py)"

The error you're encountering typically arises from a naming conflict between your project's modules and Python's standard library modules. Specifically, the error message:

pgsql
Copy
Edit
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (/home/fastapi-user/ella-brevia/brevia/collections.py)
indicates that Python is attempting to import namedtuple from your project's collections.py file instead of the built-in collections module. This happens because Python prioritizes the local directory when resolving module imports, leading to a shadowing of the standard library module.

Steps to Resolve the Issue:
Rename Your collections.py File:

Why? By renaming the file, you eliminate the conflict with Python's standard collections module.
How? Choose a name that doesn't clash with standard library modules. For example, rename it to custom_collections.py or another descriptive name relevant to its functionality.

@stefanorosanelli
Copy link
Contributor

stefanorosanelli commented Feb 3, 2025

Hi @bullemer, thank you for reporting this problem

We noticed this already, but unfortunately pylint didn't report this, so we found out too late.

The cleanest solution that comes to mind is:

  • rename the module
  • keep a temporary backward compatibility via __init__.py and deprecate the current collections module name
  • get rid of it on a future version

We'll try to introduce a quick fix very soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants