Opened 8 years ago
Closed 8 years ago
#28169 closed Bug (invalid)
Unable to disconnect signal
Reported by: | James Addison | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am looking to disconnect the post_init
signal in a management command due to exceptions it raises in my scenario. My disconnect looks like this:
signals.post_init.disconnect(ImageField.update_dimension_fields, sender=Bug)
If I'm doing something wrong, I'd love to know what.
Digging in a bit, it's caused by the fact that the lookup key generated in the .connect()
at https://github.com/django/django/blob/stable/1.11.x/django/dispatch/dispatcher.py#L105 differs from the one generated in .disconnect()
at https://github.com/django/django/blob/stable/1.11.x/django/dispatch/dispatcher.py#L153
Maybe related to #22657. See the attached project to reproduce.
Attachments (1)
Change History (3)
by , 8 years ago
Attachment: | disconnect_bug.zip added |
---|
comment:1 by , 8 years ago
Ok, so I found a way to do what I needed, but I'm not sure it 'resolves' this bug report, as it seems like a truly convoluted way to disconnect such a signal. The following will successfully disconnect the signal:
signals.post_init.disconnect(Bug._meta.get_field('image').update_dimension_fields, sender=Bug)
I will leave it to the core team to decide.
comment:2 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Hello James,
Glad you managed to achieve what you were after.
Since the actual receiver is the update_dimension_fields
method bound to the field instance, and not the unbound ImageField.update_dimension_fields
function, it makes sense that you must pass the former and not the latter.
Since disconnecting such signal receiver is not a common use case I don't believe it's worth making this any simpler. I suggest you use our support channels to get help with these kind of issues in the future to get assistance faster and gather feedback about whether or not it's worth opening an issue about it. Thanks!
Project demonstrating the issue.