There is another important reason to use update_fields:
Using the above mentioned model let's assume that one user sets the is_deleted flag to True and another user changes the name of the "record".
Let's assume that the two events happens in the order mentioned into two separate processes, in the case of using the generic save the first operation will be unwillingly reverted by the second operation, as the second process will have in memory the is_deleted=False value which therefore will save in that state.
It is clear that a project that has a high changes of contemporary operations on certain records should consider some more robust conflict management but in most of cases writing only what is required to be updated removes most of the chances of unwanted side effects.
There is another important reason to use
update_fields
:Using the above mentioned model let's assume that one user sets the
is_deleted
flag toTrue
and another user changes the name of the "record".Let's assume that the two events happens in the order mentioned into two separate processes, in the case of using the generic save the first operation will be unwillingly reverted by the second operation, as the second process will have in memory the
is_deleted=False
value which therefore will save in that state.It is clear that a project that has a high changes of contemporary operations on certain records should consider some more robust conflict management but in most of cases writing only what is required to be updated removes most of the chances of unwanted side effects.
That's true. I hadn't considered this particular use case.