Django: data modified in pre_save signal is not saved
Briefly

In my first Django project focused on tracking gym workouts, I faced an issue where modifications made in the pre_save signal were not saved to the database. This incident highlighted the importance of understanding the relationship between the pre_save signal and the update_fields argument. When using pre_save to enforce completion conditions on exercise sessions, it is crucial that any modified fields by the signal are included in update_fields during save(), or else these changes will not persist, leading to potentially incorrect application behavior. My goal in sharing this experience is to help others avoid similar pitfalls.
pre_save signal can modify the instance before saving, but if not included in update_fields, changes will not be stored in the database.
The SQL query created later in the save process will only consider fields listed in update_fields, which could lead to unexpected results.
Read at Mirek Dugosz personal website
[
|
]