Opened 17 years ago
Closed 16 years ago
#6579 closed (duplicate)
Importing empty symbol causes double initialization of some modules
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In file templatetags/__init__.py
there is a line:
__path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
__import__
method as fourth parameters gets a list of symbols to import. If this list is empty, __import__
returns the top-level package, but if the list contains anything the specified package is returned as described in http://docs.python.org/lib/built-in-funcs.html . So in this file there is a hack where not empty list but list that contains 'something' is passed - list that contains single empty name.
But it causes some strange side-effects - the specified module is initialized twice. First with correct name and later with name followed by a dot (e.g. 'prog.app.templatetags'
and 'prog.app.templatetags.'
). In some cases it may cause serious problems.
Attachments (3)
Change History (13)
by , 17 years ago
Attachment: | double_init.patch added |
---|
comment:1 by , 17 years ago
Has patch: | set |
---|
Attached patch should be used, or at least some existing name instead of should be used ( like 'name' )
by , 17 years ago
Attachment: | double_init_django_app.tgz added |
---|
simple django application that illustrates the problem
comment:3 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 17 years ago
Triage Stage: | Accepted → Unreviewed |
---|
comment:5 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:6 by , 17 years ago
Description from submission on Python bug list: http://bugs.python.org/issue2090
{{{ ...it's a hack, so supporting an abuse of the API is not
reasonable. You don't have to set the fromlist for the import to work.
And if you are doing it to get the tail module, you can write some
simple code to use getattr() to walk down from the root module to the
one you want }}}
In the next two days I will prepare a patch that will resolve similar problems in other places in Django.
comment:7 by , 17 years ago
Description: | modified (diff) |
---|
comment:8 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in latest patch to ticket #6587
comment:9 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:10 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
patch based on description in http://docs.python.org/lib/built-in-funcs.html