summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2015-07-05 17:00:21 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2015-07-05 17:04:26 +0200
commit6d190fa33f8a0cd625d3ce13d6de29bd5b72e742 (patch)
treeef7e82d0dba73c174d4beaf0c728f7d062bbbdc8
parentd471c1b4b0d4b06d557b5b6a9349a7dc55515d69 (diff)
downloadfactory-boy-6d190fa33f8a0cd625d3ce13d6de29bd5b72e742.tar
factory-boy-6d190fa33f8a0cd625d3ce13d6de29bd5b72e742.tar.gz
Improve @coagulant's fixes to django signals (Closes #212).
Signal caching didn't exist until Django 1.6.
-rw-r--r--factory/django.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/factory/django.py b/factory/django.py
index 5cc2b31..b2af12c 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -268,6 +268,9 @@ class mute_signals(object):
logger.debug('mute_signals: Disabling signal handlers %r',
signal.receivers)
+ # Note that we're using implementation details of
+ # django.signals, since arguments to signal.connect()
+ # are lost in signal.receivers
self.paused[signal] = signal.receivers
signal.receivers = []
@@ -277,8 +280,12 @@ class mute_signals(object):
receivers)
signal.receivers = receivers
- with signal.lock:
- signal.sender_receivers_cache.clear()
+ if django.VERSION[:2] >= (1, 6):
+ with signal.lock:
+ # Django uses some caching for its signals.
+ # Since we're bypassing signal.connect and signal.disconnect,
+ # we have to keep messing with django's internals.
+ signal.sender_receivers_cache.clear()
self.paused = {}
def copy(self):