django.utils.module_loading.module_has_submodule yields false positives
|Reported by:||Łukasz Rekucki||Owned by:||nobody|
|Cc:||Michael Shields||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by )
The way I found this is a bit crazy, so I'm not going to describe it all, but the 2 important things are:
- I have some explicit relative imports.
- I wanted to make a template library named the same as the application it contains.
This generally should work (tried on a fresh project), but failed with a weird error in my project:
"'currencies' is not a valid tag library: ImportError raised loading company.templatetags.currencies: No module named currencies". Of course there is no such module, because it's on "currencies.templatags" application.
So after some debuging it turned out that module_has_submodule returns a false positive. This is because it checks
if name in sys.modules . To be honest, I didn't know about this, but it seems that Python sometimes also stores import misses by puting a None in to that dictionary. See this python-dev thread.
Change History (8)
comment:1 Changed 6 years ago by
|Patch needs improvement:||unset|
comment:2 Changed 6 years ago by
|Component:||Uncategorized → Core framework|
|Triage Stage:||Unreviewed → Ready for checkin|