Code

Opened 4 years ago

Last modified 23 months ago

#13080 new Bug

Documentation bug for Signal.connect

Reported by: george.sakkis@… Owned by: nobody
Component: Documentation Version: 1.2-beta
Severity: Normal Keywords: signals
Cc: real.human@…, mmitar@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Signal.connect says about the optional sender keyword "Must either be of type Signal, or None to receive events from any sender", but actually sender can be any any python object.

Attachments (0)

Change History (7)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

To clarify: This is a comment about the docstring on Signal.connect, line 59 of django/dispatch/dispatcher.py

(Note for future reference -- if you're going to make a bug report, it helps to point out *where* the bug is)

comment:2 Changed 4 years ago by russellm

See #13132 for a related issue that requires clarification when the documentation surrounding sender is updated.

comment:3 follow-up: Changed 3 years ago by mrmachine

  • Cc real.human@… added

Actually, it can't be any python object. It seems to only work somewhat reliably with classes, and even then you might experience double registration which is why we have the dispatch_uid argument. This seems buggy to me. It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems. It should work as specified, or not, and preferably with "any python object" as the docstrings indicate. This would make it possible to connect receiver functions to signals sent by specific model instances, or senders that have nothing to do with models at all using a string literal sender.

comment:4 Changed 3 years ago by lukeplant

  • Type set to Bug

comment:5 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:6 Changed 2 years ago by mitar

  • Cc mmitar@… added
  • Easy pickings unset
  • UI/UX unset

comment:7 in reply to: ↑ 3 Changed 23 months ago by jdunck

Replying to mrmachine:

Actually, it can't be any python object. It seems to only work somewhat reliably with classes, and even then you might experience double registration which is why we have the dispatch_uid argument. This seems buggy to me. It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems. It should work as specified, or not, and preferably with "any python object" as the docstrings indicate. This would make it possible to connect receiver functions to signals sent by specific model instances, or senders that have nothing to do with models at all using a string literal sender.

It would be better, but it isn't practical. "It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems" - the issue is that the identity of an object in python is basically its memory address. dispatch_uid is to provide a canonical, well-known name for the given receiver. If dispatch_uid is not given, then if receiver happens to be two different objects (as happens when the same module is imported with different pathing, or when the receiver is a dynamically-created function), then there isn't a practical way to know it's the same receiver.

Additionally, we settled on a const-string as the fallback because performance overhead in the signals system is critical. pre_init and post_init are fatally performance-sensitive design choices, and dominate any consideration of changes in signals. String comparison is the simplest way to perform the needed human-readable, performance-sensitive equality comparison.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.