django-simple-history
django-simple-history copied to clipboard
Does not take into account 'update_fields'
trafficstars
Describe the bug If you use 'update_fields' parameter in entity.save() method, the library record in history all fields that you changed before save(), but not only that in 'update_fields'.
To Reproduce Steps to reproduce the behavior:
- Get entity: entity_db = Entity.objects.get(pk=1)
- Change some fields: entity_db.some_field = 'new_value_1', entity_db.other_field = 'new_value_2'
- Save using the parameter 'update_fields': entity.save(update_fields=['some_field'])
- In Db Entity will have some_field == 'new_value_1' and other_field == 'old_value'
- But in historicalentity Table you will see that library make a record with some_field == 'new_value_1' and other_field == 'new_value_2'
Expected behavior In historicalentity Table: some_field == 'new_value_1' and other_field == 'old_value'
Environment (please complete the following information):
- Django Simple History Version: [e.g. 3.2.0]
- Django Version: [e.g. 4.0.6]
if you run save_without_historical_record, the update_fields does act as expected. (however, then lose out on the history)
Faced with this weird behavior today. It would be super nice to have this fix.