From 20b598bf3e430ac969f06c290ab69555b9604922 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sun, 5 Apr 2009 17:20:38 +0000 Subject: [PATCH] Fixed #9989: fixed a subtle edge case where removing signals could break. Thanks, ferringb. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10398 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/dispatch/dispatcher.py | 7 ++++--- tests/modeltests/signals/models.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py index 74fdd20b90..bb60fc906d 100644 --- a/django/dispatch/dispatcher.py +++ b/django/dispatch/dispatcher.py @@ -119,10 +119,11 @@ class Signal(object): lookup_key = (dispatch_uid, _make_id(sender)) else: lookup_key = (_make_id(receiver), _make_id(sender)) - - for idx, (r_key, _) in enumerate(self.receivers): + + for index in xrange(len(self.receivers)): + (r_key, _) = self.receivers[index] if r_key == lookup_key: - del self.receivers[idx] + del self.receivers[index] def send(self, sender, **named): """Send signal from sender to all connected receivers. diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py index 5e038f9516..06fd3a6fb3 100644 --- a/tests/modeltests/signals/models.py +++ b/tests/modeltests/signals/models.py @@ -96,4 +96,15 @@ instance.id is None: False >>> models.signals.pre_delete.disconnect(pre_delete_test) >>> models.signals.post_save.disconnect(post_save_test) >>> models.signals.pre_save.disconnect(pre_save_test) + +# Make sure all the signals got removed properly (#9989) +>>> models.signals.post_delete.receivers +[] +>>> models.signals.pre_delete.receivers +[] +>>> models.signals.post_save.receivers +[] +>>> models.signals.pre_save.receivers +[] + """}