Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 9 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Build/flake8/isort aren't passing.

comment:2 by Alex Hill, 9 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 Tim Graham, 9 years ago

Patch needs improvement: unset

comment:4 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In ff6c6fe:

Fixed #26642 -- Made ModelSignal.disconnect() work with lazy references.

comment:5 by Tim Graham <timograham@…>, 8 years ago

In f91247f:

[1.10.x] Fixed #26642 -- Made ModelSignal.disconnect() work with lazy references.

Backport of ff6c6feae17120c2c7df74fb6a9dc76826a1e233 from master

Note: See TracTickets for help on using tickets.
Back to Top