#35801: Signals are dispatched to receivers associated with dead senders
------------------------------+--------------------------------------
     Reporter:  bobince       |                    Owner:  (none)
         Type:  Bug           |                   Status:  closed
    Component:  Core (Other)  |                  Version:  5.1
     Severity:  Normal        |               Resolution:  needsinfo
     Keywords:                |             Triage Stage:  Unreviewed
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+--------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => needsinfo
 * status:  new => closed

Comment:

 Hello bobince, thank you for taking the time to create this ticket report.

 I have investigated and I have used the code that you shared to reproduce.
 I applied a small change because I don't think it's correct to clear
 `receivers_called = []` like that inside the loop. I also added some
 `kwargs` when sending the `Signal` to ensure we are debugging the right
 thing. What I find more "correct" is the following, which unless I'm
 missing something should be equivalent to your proposal. Sadly, this does
 not fail for me at any iteration (I even increased `n` to be `1000`):

 {{{#!python
 from collections import defaultdict

 from django.dispatch import Signal


 signal_calls = defaultdict(list)


 def create_receiver(i):
     def receiver(sender, **kwargs):
         signal_calls[i].append((sender, kwargs))

     return receiver


 n = 1000
 receivers = [create_receiver(i) for i in range(n)]
 signal = Signal()
 for i in range(n):
     sender = object()
     signal.connect(receivers[i], sender=sender)
     _ = signal.send(sender=sender, i=i)
     # only the receiver for the new sender object should be called
     expected = [(sender, {"signal": signal, "i": i})]
     assert signal_calls[i] == expected, f"{expected=}, got
 {signal_calls=}"
 }}}

 Do you think you could, instead of a script, provide a failing test case
 for the Django test suite to illustrate the issue you are describing?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35801#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701924e66daca-26d5a301-004e-482c-9c0a-af18b1e59bb3-000000%40eu-central-1.amazonses.com.

Reply via email to