Code

Opened 6 years ago

Closed 6 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: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by ramiro)

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@…> 6 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@…> 6 years ago.
simple python test illustrating the problem
double_init_django_app.tgz (2.3 KB) - added by Grzegorz Lukasik <hauserx@…> 6 years ago.
simple django application that illustrates the problem

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

comment:1 Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

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

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

comment:2 Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

The same construction is used in few places in django.

Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

simple python test illustrating the problem

Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

simple django application that illustrates the problem

comment:3 Changed 6 years ago by anonymous

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 6 years ago by anonymous

  • Triage Stage changed from Accepted to Unreviewed

comment:5 Changed 6 years ago by Simon Greenhill

  • Triage Stage changed from Unreviewed to Accepted

comment:6 Changed 6 years ago by Grzegorz Lukasik <hauserx@…>

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

  • Description modified (diff)

comment:8 Changed 6 years ago by oyvind

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

Fixed in latest patch to ticket #6587

comment:9 Changed 6 years ago by ramiro

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:10 Changed 6 years ago by ramiro

  • Resolution set to duplicate
  • Status changed from reopened to closed

(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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.