Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14698 closed (fixed)

django.utils.module_loading.module_has_submodule yields false positives

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

Description (last modified by ramiro)

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.

Attachments (1)

python_import_misses.diff (595 bytes) - added by lrekucki 4 years ago.

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by lrekucki

comment:1 Changed 4 years ago by lrekucki

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by russellm

  • Component changed from Uncategorized to Core framework
  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 4 years ago by shields

  • Cc shields added

comment:4 Changed 4 years ago by shields

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 Changed 4 years ago by ramiro

  • Description modified (diff)

(re-formatted description)

comment:6 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [15362]) Fixed #14698 -- Ensure that module_has_sumodule doesn't mistake a cache miss for an existent package. Thanks to Łukasz Rekucki for the report and patch, and to shields for the test case.

comment:7 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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