Django

Code

Ticket #6579 (closed: duplicate)

Opened 10 months ago

Last modified 1 month ago

Importing empty symbol causes double initialization of some modules

Reported by: Grzegorz Lukasik <hauserx@gmail.com> Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

double_init.patch (0.6 kB) - added by Grzegorz Lukasik <hauserx@gmail.com> on 02/11/08 16:13:20.
patch based on description in http://docs.python.org/lib/built-in-funcs.html
python_test.tgz (323 bytes) - added by Grzegorz Lukasik <hauserx@gmail.com> on 02/11/08 16:22:54.
simple python test illustrating the problem
double_init_django_app.tgz (2.3 kB) - added by Grzegorz Lukasik <hauserx@gmail.com> on 02/11/08 16:41:03.
simple django application that illustrates the problem

Change History

02/11/08 16:13:20 changed by Grzegorz Lukasik <hauserx@gmail.com>

  • attachment double_init.patch added.

patch based on description in http://docs.python.org/lib/built-in-funcs.html

02/11/08 16:14:45 changed by Grzegorz Lukasik <hauserx@gmail.com>

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

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

02/11/08 16:16:58 changed by Grzegorz Lukasik <hauserx@gmail.com>

The same construction is used in few places in django.

02/11/08 16:22:54 changed by Grzegorz Lukasik <hauserx@gmail.com>

  • attachment python_test.tgz added.

simple python test illustrating the problem

02/11/08 16:41:03 changed by Grzegorz Lukasik <hauserx@gmail.com>

  • attachment double_init_django_app.tgz added.

simple django application that illustrates the problem

02/14/08 07:23:16 changed by anonymous

  • stage changed from Unreviewed to Accepted.

02/14/08 07:23:24 changed by anonymous

  • stage changed from Accepted to Unreviewed.

06/14/08 06:46:12 changed by Simon Greenhill

  • stage changed from Unreviewed to Accepted.

06/20/08 11:50:58 changed by Grzegorz Lukasik <hauserx@gmail.com>

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.

06/23/08 13:00:12 changed by ramiro

  • description changed.

07/01/08 15:17:14 changed by oyvind

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in latest patch to ticket #6587

11/02/08 14:20:52 changed by ramiro

  • status changed from closed to reopened.
  • resolution deleted.

11/02/08 14:25:09 changed by ramiro

  • status changed from reopened to closed.
  • resolution set to duplicate.

(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/Change #6579 (Importing empty symbol causes double initialization of some modules)




Change Properties
Action