#4102: Allow UPDATE of only specific fields in model.save()
-------------------------------------+-------------------------------------
     Reporter:  Collin Grady         |                    Owner:  cgrady
  <cgrady@…>                         |                   Status:  new
         Type:  New feature          |                  Version:  SVN
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  1
     Keywords:  update fields sql    |  Patch needs improvement:  1
  row table modified                 |                    UI/UX:  0
    Has patch:  1                    |
  Needs tests:  1                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * needs_tests:  0 => 1


Comment:

 A couple of design considerations:
   - if only fields is given should it imply force_update=True. My take is
 yes, as I don't think there will be a use case for only_fields + insert.
 Set the field values to NULL instead. In addition only_fields + insert
 could lead to some complicated situations. So, maybe the kwarg should
 instead be update_fields?
   - what if the model does not have fields given in the update_fields
 argument? Should it be an error or not. I guess erroring out could be
 wise, as otherwise this could hide data loss bugs. This should probably be
 done in .save() as a pre-check, and then .save_base just uses the given
 set without further checks.
   - It might make sense to add the field set to pre/post save signals as
 an argument if this is doable from backwards compatibility viewpoint.
   - Should a deferred model which is then saved have automatically
 update_fields set so that only the non-deferred fields will be saved. I
 think currently the fields are loaded from the database and then the
 update will update the fields to the just fetched values which does not
 make sense.

 This should be tested with model inheritance, too. It is a common pain-
 point for this kind of feature. The current test doesn't actually seem to
 test that the name is updated, so in general more tests needed.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/4102#comment:75>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to