#27340: Model pre_init signal should provide an `instance` argument
-------------------------------------+-------------------------------------
     Reporter:  Ask Solem Hoel       |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Ask Solem Hoel):

 lol, you want an example.  Brace yourself, will probably be more difficult
 to understand, but here:

 https://github.com/robinhood/thorn/blob/master/thorn/django/signals.py#L39-L44

 we use the pre)save signal to store a snapshot of how the model looked
 like before it was changed


 With the proposed change we'd be able to avoid doing two database queries
 for every Model.save by doing this:


 @signals.pre_init.connect
 def _track_changes(instance, args, kwargs, **kwargs):
     instance._original_args = args, kwargs

 There's no other way as far as I can find, as we don't want to monkeypatch
 Model, and in any case it's very strange that the pre_init signal omits
 the instance being created.

--
Ticket URL: <https://code.djangoproject.com/ticket/27340#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.cc2d07408b53019f07ed28218b15b8f3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to