Opened 17 years ago

Closed 16 years ago

#6579 closed (duplicate)

Importing empty symbol causes double initialization of some modules

Reported by: Grzegorz Lukasik <hauserx@…> 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 Ramiro Morales)

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)

double_init.patch (595 bytes ) - added by Grzegorz Lukasik <hauserx@…> 17 years ago.
patch based on description in http://docs.python.org/lib/built-in-funcs.html
python_test.tgz (323 bytes ) - added by Grzegorz Lukasik <hauserx@…> 17 years ago.
simple python test illustrating the problem
double_init_django_app.tgz (2.3 KB ) - added by Grzegorz Lukasik <hauserx@…> 17 years ago.
simple django application that illustrates the problem

Download all attachments as: .zip

Change History (13)

by Grzegorz Lukasik <hauserx@…>, 17 years ago

Attachment: double_init.patch added

comment:1 by Grzegorz Lukasik <hauserx@…>, 17 years ago

Has patch: set

Attached patch should be used, or at least some existing name instead of should be used ( like 'name' )

comment:2 by Grzegorz Lukasik <hauserx@…>, 17 years ago

The same construction is used in few places in django.

by Grzegorz Lukasik <hauserx@…>, 17 years ago

Attachment: python_test.tgz added

simple python test illustrating the problem

by Grzegorz Lukasik <hauserx@…>, 17 years ago

Attachment: double_init_django_app.tgz added

simple django application that illustrates the problem

comment:3 by anonymous, 17 years ago

Triage Stage: UnreviewedAccepted

comment:4 by anonymous, 17 years ago

Triage Stage: AcceptedUnreviewed

comment:5 by Simon Greenhill, 16 years ago

Triage Stage: UnreviewedAccepted

comment:6 by Grzegorz Lukasik <hauserx@…>, 16 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 Ramiro Morales, 16 years ago

Description: modified (diff)

comment:8 by oyvind, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in latest patch to ticket #6587

comment:9 by Ramiro Morales, 16 years ago

Resolution: fixed
Status: closedreopened

comment:10 by Ramiro Morales, 16 years ago

Resolution: duplicate
Status: reopenedclosed

(changed resolution from fixed to duplicate) In regard to the template loader, this is solved with the patch proposed in #6587. The general case has been reported in #8193.

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