To leap in here - we use post_init in our application, so there's at least *one* consumer out there! We use them to populate attributes on a model which depend on other system state, including data in that model itself. In our case, we actually only care about the instance passed in kwargs.
There may be another way of doing what we're doing without post_init, but I'd need to look into it.
Cheers
Dan
--
Dan Fairs | dan....@gmail.com | www.fezconsulting.com
Really stupid question, but why not just override __init__? Third party
code, where you can't modify the __init__?
But, maybe these signals do not need to be deprecated to get the speed
gain. We could check if pre_init or post_init is used at all in the
Django instance. This would be done by using global variables
has_pre_init_listeners and has_post_init_listeners in
django/db/models/base.py. These variables are set when first listener is
registered to pre_init and post_init signals. If there is one (for any
model), then do the normal signal sending. So, instead of doing:
singnals.pre_init.send(sender=...)
do
if has_pre_init_listeners:
signals.pre_init.send(sender=...)
That way, if there is no listeners at all defined, the overhead should
be non-measurable. Hopefully this is the common case.
Currently, the signal.send() calls add about 0.02 seconds to 10000
objects (on my old laptop). If there is any listener on pre_init or
post_init, the overhead of that is 0.05 seconds, no matter if the
listener is interested in the current model or not. That is, a listener
for T1 will add 0.05 seconds to initializations of T2. There is a
further small penalty for signals actually interested in the current
model. It is something like 0.03 seconds if I remember correctly.
- Anssi