python file names colide with global scope variables/modules #430
Replies: 1 comment
-
@franciscobmacedo Thanks for a really well specified bug report. I agree that this is not optimal behaviour. There's probably an easy fix that entails putting the components in the a component specific scope instead of the global one. I'll happily accept patches that changes that. Let's continue the discussion in this issue: #431 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem
If a component directory has python files in it that are named after some global scope variable name or module of another library, it overrides that variable. This causes a big problem: I can't name my python files after any global scope variable in my project.
Example
I have a simple component called "select". the file structure is something like this:
However, I also use celery, which uses the select I/O module from the standard library. When launching a celery task, it was causing this error:
Mostly because in my component
select.py
file I don't really have anything namedselect
. For testing purposes I added an empty "django.py" file in that directory, and sure enough the same problem happens:PS: The variable names inside the python file and the registered component name don't cause any issues. It's only the python file(s) name(s) inside a component directory.
Current solution
If I set the
COMPONENTS
settings variable to disable autodiscover, this is all fixed:Proposed ideas
I understand the problem lies somewhere in the import_file function, where each component is registered as an independent module and therefore overriding already existing ones.
I'm not adding this problem as an issue because there's a solution for it. However, I believe this is a limitation: I think one should be able to name a component python file "select.py" and not worry about repercussions. Or, at least, maybe this could be more explicit in the README.md?
I don't want by all means complain, I love this project, so thank you very much for it!! Just thought this can be a problem for others as well.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions