Ticket #11134: 11134-against-10791.diff

File 11134-against-10791.diff, 2.3 KB (added by Honza Král, 15 years ago)
  • django/dispatch/dispatcher.py

    diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
    index 07377d6..31c4923 100644
    a b class Signal(object):  
    192192        receivers.
    193193        """
    194194        none_senderkey = _make_id(None)
     195        receivers = []
    195196
    196197        for (receiverkey, r_senderkey), receiver in self.receivers:
    197198            if r_senderkey == none_senderkey or r_senderkey == senderkey:
    class Signal(object):  
    199200                    # Dereference the weak reference.
    200201                    receiver = receiver()
    201202                    if receiver is not None:
    202                         yield receiver
     203                        receivers.append(receiver)
    203204                else:
    204                     yield receiver
     205                    receivers.append(receiver)
     206        return receivers
    205207
    206208    def _remove_receiver(self, receiver):
    207209        """Remove dead receivers from connections."""
  • tests/modeltests/signals/models.py

    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.  
    33"""
    44
    55from django.db import models
     6from django.db.models import signals
     7
     8from django.test import TestCase
    69
    710class Person(models.Model):
    811    first_name = models.CharField(max_length=20)
    class PostDeleteHandler(object):  
    3841
    3942post_delete_test = PostDeleteHandler()
    4043
     44
     45class 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
     55class 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
    4168__test__ = {'API_TESTS':"""
    4269
    4370# Save up the number of connected signals so that we can check at the end
Back to Top