Handle subclasses in signal dispatcher
|Reported by:||Patryk Zawadzki||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently the signal dispatcher stores just the identity of the passed object instead. Because of that the
_live_receivers method can only perform equality tests. The result is that the moment you use Python inheritance for models, the signals stop working.
You can work around that by setting sender to
None but it adds a bit of an overhead due to the fact that your handler is called for each and every object and there are places where you can't change how signals are connected (like the generic relations).
Therefore I propose modifying the
_make_id function a bit so when passed a type (class) or a list/tuple of types it returns it verbatim without identity casting. Then
_live_receivers could test for
issubclass dealing with classes.
While this would technically result in a different behavior from what Django 1.3 does, I doubt it would be a problem. I don't think there are many cases when you want a signal from a base class but not from subclasses and the few remaining uses can manually test for that in the handler.