Re: [Django] #27340: Model pre_init signal should provide an `instance` argument

2016-10-26 Thread Django
#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: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
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.


Re: [Django] #27340: Model pre_init signal should provide an `instance` argument

2016-10-22 Thread Django
#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
-+-
Changes (by Tim Graham):

 * status:  new => closed
 * resolution:   => needsinfo


--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.95a9c6a805130b0d3b403277e0c53f4d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27340: Model pre_init signal should provide an `instance` argument

2016-10-13 Thread Django
#27340: Model pre_init signal should provide an `instance` argument
-+-
 Reporter:  Ask Solem Hoel   |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.10
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 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 Tim Graham):

 Could you provide an example of your existing code and what it would look
 like after this change? I'll check that I don't see another way to
 accomplish your use case.

--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.a80affa52bddc8a5798a13684b684cfd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27340: Model pre_init signal should provide an `instance` argument

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

 * needs_docs:   => 0
 * needs_better_patch:   => 0
 * component:  Uncategorized => Database layer (models, ORM)
 * needs_tests:   => 0
 * type:  Uncategorized => New feature


--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.ec4b4acd3ad497522e2432d3dba745cb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #27340: Model pre_init signal should provide an `instance` argument

2016-10-12 Thread Django
#27340: Model pre_init signal should provide an `instance` argument
+
 Reporter:  Ask Solem Hoel  |  Owner:  nobody
 Type:  Uncategorized   | Status:  new
Component:  Uncategorized   |Version:  1.10
 Severity:  Normal  |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0   |  UI/UX:  0
+
 I struggle to find reasons as to why this argument is ommitted.

 The current signature for pre_init is:

 {{{
 class Model(six.with_metaclass(ModelBase)):
 _deferred = False

 def __init__(self, *args, **kwargs):
 signals.pre_init.send(sender=self.__class__, args=args,
 kwargs=kwargs)
 }}}

 I suggest that the signature should be:

 {{{
 class Model(six.with_metaclass(ModelBase)):
 _deferred = False

 def __init__(self, *args, **kwargs):
 signals.pre_init.send(sender=self.__class__, args=args,
 kwargs=kwargs, instance=self)
 }}}

 Or alternatively, that the `post_init` signal contains the args and kwargs
 used to construct the model.

 The reason for wanting access to the instance in pre_init is that I want
 to track changes
 to the model since it was first retrieved from the database - This is
 currently not possible without subclassing Model,
 and that is not a realistic option for us as we deal with third party
 models.

 The current way we handle this is by using `pre_save` to fetch the row
 from the database again, but this is suboptimal
 and this a simple change would allow us to do this.

--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/046.fc94fb75509c1f2b46e962efc1fa2670%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.