#10095: __import__ behaviour causing signal receivers to be connected twice
----------------------------+-----------------------------------------------
Reporter: ben | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: SVN
Keywords: signal import | Stage: Unreviewed
Has_patch: 0 |
----------------------------+-----------------------------------------------
When connecting a signal we had an issue where it was getting connected
twice.
The signal receivers were both defined and connected in the project's
{{{__init__.py}}}
I've tracked this down to the use of {{{__import__('somemod', {}, {},
[''])}}} specifically in core.management.setup_environ (line 251 in my
checkout of django which is at rev 7305): this line:
{{{
#!python
project_module = __import__(project_name, {}, {}, [''])
}}}
An import like this with an empty string in the fromlist arg causes my
project to be imported - and therefore evaluated - twice. The second time
it's imported it's added to sys.modules with the key being
'<module_name>.' and the ids of the signal functions are different. This
screws up the signal connection which is keyed off the id resulting in the
function being connected twice.
This is probably only going to be a problem for people connecting signals
in the root of their project (I count 27 time in my version of the django
source where this idiom is used). However I do wonder whether it's worth
making the django.dispatch.dispatcher.connect function more robust with
this in mind. (I guess this might have already been done in the signal
refactor?)
See [http://bugs.python.org/issue2090] and
[http://bugs.python.org/issue4438]
--
Ticket URL: <http://code.djangoproject.com/ticket/10095>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---