Opened 17 years ago

Last modified 16 years ago

#6579 closed

Importing empty symbol causes double initialization of some modules — at Version 7

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.

Change History (10)

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)
Note: See TracTickets for help on using tickets.
Back to Top