#26642 closed Bug (fixed)
ModelSignal.disconnect() does not work with lazy references
Reported by: | Alex Hill | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ModelSignal.connect()
lets you pass a string model reference as a sender, and will connect the signal as soon as the model is available.
For consistency, ModelSignal.disconnect()
should work in the same way. Currently, if you call connect()
followed by disconnect()
before the model is available, the signal will remain connected:
>>> def receiver(sender, **kwargs): ... print("post_init sent by %r" % sender) ... >>> post_init.connect(receiver, sender='some_app.SomeModel') >>> post_init.disconnect(receiver, sender='some_app.SomeModel') False >>> >>> class SomeModel(models.Model): ... class Meta: ... app_label = 'some_app' ... >>> s = SomeModel() post_init sent by <class 'SomeModel'> >>>
There's a patch with the necessary changes in PR 6629.
Change History (5)
comment:1 by , 8 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 8 years ago
Sorry, that was sloppy. I've updated the patch. Strange for a circular import to only cause a problem in 2.7.
comment:3 by , 8 years ago
Patch needs improvement: | unset |
---|
Note:
See TracTickets
for help on using tickets.
Build/flake8/isort aren't passing.