﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10095	__import__ behaviour causing signal receivers to be connected twice	ben	nobody	"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]"		closed	Core (Other)	dev		duplicate	signal import		Unreviewed	0	0	0	0	0	0
