Opened 13 years ago

Last modified 13 years ago

#14698 closed

django.utils.module_loading.module_has_submodule yields false positives — at Version 5

Reported by: Łukasz Rekucki Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords:
Cc: Michael Shields Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

The way I found this is a bit crazy, so I'm not going to describe it all, but the 2 important things are:

  1. I have some explicit relative imports.
  2. 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 (6)

by Łukasz Rekucki, 13 years ago

Attachment: python_import_misses.diff added

comment:1 by Łukasz Rekucki, 13 years ago

Has patch: set

comment:2 by Russell Keith-Magee, 13 years ago

Component: UncategorizedCore framework
milestone: 1.3
Triage Stage: UnreviewedReady for checkin

comment:3 by Michael Shields, 13 years ago

Cc: Michael Shields added

comment:4 by Michael Shields, 13 years ago

I reported this in 15114 which was a duplicate. But you may want to include the regression test I wrote.

http://code.djangoproject.com/attachment/ticket/15114/sys-modules-none.diff

comment:5 by Ramiro Morales, 13 years ago

Description: modified (diff)

(re-formatted description)

Note: See TracTickets for help on using tickets.
Back to Top