|Model.save() incompatibilities||Anssi Kääriäinen||8/28/13 1:23 AM|
I just created a new ticket (https://code.djangoproject.com/ticket/20988), and marked it as release blocker for 1.6.
The summary of the issue is that there are some cases where the new save() algorithm will not save existing objects (for details about the algorithm, see #20988). This happens when an UPDATE of an existing row returns zero matched rows. At least PostgreSQL ON UPDATE triggers returning NULL can cause this condition. If an user is hit by this issue, then currently the options are to remove the trigger, or to use raw SQL for update of existing objects. There might be 3rd party backends or other conditions where the only option is raw SQL.
It would be nice to have better alternatives than raw SQL. Some options:
- Change back to old algorithm.
- Change the Model._do_update() to include forced_update flag. If this is done, it will be possible to override to _do_update() to use the old style algorithm. Unfortunately _do_update() is private API, but using that is likely better for most users than raw SQL.
- Add a select_on_save flag now, that is before release. The flag effectively forces use of the old algorithm. The implementation is straightforward, see https://github.com/akaariai/django/commit/1ca398b0352b11868ec236f92cf17b6ce82ff88c. Docs missing, but otherwise ready.
- Wait and see. If there are enough complaints, add select_on_save or some other workaround later on (that is, mid 1.6, or in 1.7).
In addition, better release notes about this issue are needed.
I think reverting to the old algorithm isn't a good option. The new algorithm will save one query in most cases. I will do the _do_update() signature change now, it is good for those who want to use that particular private API in any case.
The real question is should something be done about select_on_save flag now?
|Re: Model.save() incompatibilities||Marc Tamlyn||8/28/13 1:44 AM|
I think we should implement `select_on_save`. It gives the easiest way for someone to revert the feature if they need to. I know we're adding another Meta flag, but I'm not that concerned about that.
|Re: Model.save() incompatibilities||Anssi Kääriäinen||8/28/13 2:04 AM|
I'll try to write a ready-for-checking patch ASAP. It is easier to discuss about concrete and full patch.
|Re: Model.save() incompatibilities||Anssi Kääriäinen||8/28/13 3:27 AM|
On Wednesday, August 28, 2013 12:04:40 PM UTC+3, Anssi Kääriäinen wrote:
Not quite ready yet, but patches for 1.6.x and master can be found from:
Proofread of docs needed. Reviews in general are very much welcome.
The select_on_save flag is a new feature (although a minor one). Any objections of adding it at this stage to 1.6?