From 6d190fa33f8a0cd625d3ce13d6de29bd5b72e742 Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Sun, 5 Jul 2015 17:00:21 +0200 Subject: Improve @coagulant's fixes to django signals (Closes #212). Signal caching didn't exist until Django 1.6. --- factory/django.py | 11 +++++++++-- 1 file 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): -- cgit v1.2.3