DEV Community

loading...

Discussion on: Save your Django models using update_fields for better performance

Collapse
paoloc68 profile image
Paolo Calvi

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.

Collapse
sankalpjonna profile image
CH S Sankalp jonna Author

That's true. I hadn't considered this particular use case.