#16649: Models.save() refactoring: check updated rows to determine action
-------------------------------------+-------------------------------------
     Reporter:  akaariai             |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |                  Version:  1.3
    Component:  Database layer       |               Resolution:  fixed
  (models, ORM)                      |             Triage Stage:  Ready for
     Severity:  Normal               |  checkin
     Keywords:                       |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 While using update_fields on one of my projects I noticed a possible
 reason to revert the way update count is used in this ticket's committed
 patch. On PostgreSQL, if there is a trigger for the updated table, and
 this trigger returns NULL in some conditions, then the UPDATE statement is
 seen as affecting zero rows. This will result in Django seeing zero rows
 updated, and this again will result in error when using update_fields as
 the update didn't seem to affect any rows.

 For plain .save() in 1.6 the result will be IntegrityError - the update
 doesn't seem to affect any rows, but there is a row matching the update
 condition in the DB, so Django will try to UPDATE, see no rows matched,
 and then try to INSERT -> boom.

 The end result is that code that worked in 1.5 will not work in 1.6 if
 there are ON UPDATE triggers which return NULL. I am not sure about how
 common this condition will be. It will be easy to change the detection in
 save_base() from UPDATE - if not updated - INSERT to SELECT - if found
 UPDATE - else INSERT. But I would like to wait and see if this problem is
 common enough to worry about...

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16649#comment:12>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to