mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #11134: signals recievers that disconnect during their processing no longer mess things up for other handlers. Thanks, Honza Kral.
While I was at it I also cleaned up the formatting of the docstrings a bit. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ca365b4113
commit
c935d7ffe3
2 changed files with 128 additions and 75 deletions
28
tests/modeltests/signals/tests.py
Normal file
28
tests/modeltests/signals/tests.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.db.models import signals
|
||||
from django.test import TestCase
|
||||
from modeltests.signals.models import Person
|
||||
|
||||
class MyReceiver(object):
|
||||
def __init__(self, param):
|
||||
self.param = param
|
||||
self._run = False
|
||||
|
||||
def __call__(self, signal, sender, **kwargs):
|
||||
self._run = True
|
||||
signal.disconnect(receiver=self, sender=sender)
|
||||
|
||||
class SignalTests(TestCase):
|
||||
def test_disconnect_in_dispatch(self):
|
||||
"""
|
||||
Test that signals that disconnect when being called don't mess future
|
||||
dispatching.
|
||||
"""
|
||||
a, b = MyReceiver(1), MyReceiver(2)
|
||||
signals.post_save.connect(sender=Person, receiver=a)
|
||||
signals.post_save.connect(sender=Person, receiver=b)
|
||||
p = Person.objects.create(first_name='John', last_name='Smith')
|
||||
|
||||
self.failUnless(a._run)
|
||||
self.failUnless(b._run)
|
||||
self.assertEqual(signals.post_save.receivers, [])
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue