diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
index 07377d6..31c4923 100644
a
|
b
|
class Signal(object):
|
192 | 192 | receivers. |
193 | 193 | """ |
194 | 194 | none_senderkey = _make_id(None) |
| 195 | receivers = [] |
195 | 196 | |
196 | 197 | for (receiverkey, r_senderkey), receiver in self.receivers: |
197 | 198 | if r_senderkey == none_senderkey or r_senderkey == senderkey: |
… |
… |
class Signal(object):
|
199 | 200 | # Dereference the weak reference. |
200 | 201 | receiver = receiver() |
201 | 202 | if receiver is not None: |
202 | | yield receiver |
| 203 | receivers.append(receiver) |
203 | 204 | else: |
204 | | yield receiver |
| 205 | receivers.append(receiver) |
| 206 | return receivers |
205 | 207 | |
206 | 208 | def _remove_receiver(self, receiver): |
207 | 209 | """Remove dead receivers from connections.""" |
diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py
index ea8137f..ab4da2f 100644
a
|
b
|
Testing signals before/after saving and deleting.
|
3 | 3 | """ |
4 | 4 | |
5 | 5 | from django.db import models |
| 6 | from django.db.models import signals |
| 7 | |
| 8 | from django.test import TestCase |
6 | 9 | |
7 | 10 | class Person(models.Model): |
8 | 11 | first_name = models.CharField(max_length=20) |
… |
… |
class PostDeleteHandler(object):
|
38 | 41 | |
39 | 42 | post_delete_test = PostDeleteHandler() |
40 | 43 | |
| 44 | |
| 45 | class MyReceiver(object): |
| 46 | def __init__(self, param): |
| 47 | self.param = param |
| 48 | self._run = False |
| 49 | |
| 50 | def __call__(self, signal, sender, **kwargs): |
| 51 | self._run = True |
| 52 | signal.disconnect(receiver=self, sender=sender) |
| 53 | |
| 54 | |
| 55 | class TestDisconnectInReceiver(TestCase): |
| 56 | def test_two_receivers_work_fine(self): |
| 57 | a, b = MyReceiver(1), MyReceiver(2) |
| 58 | signals.post_save.connect(sender=Person, receiver=a) |
| 59 | signals.post_save.connect(sender=Person, receiver=b) |
| 60 | p1 = Person(first_name='John', last_name='Smith') |
| 61 | p1.save() |
| 62 | assert a._run |
| 63 | assert b._run |
| 64 | assert [] == signals.post_save.receivers |
| 65 | |
| 66 | |
| 67 | |
41 | 68 | __test__ = {'API_TESTS':""" |
42 | 69 | |
43 | 70 | # Save up the number of connected signals so that we can check at the end |