django-simple-history icon indicating copy to clipboard operation
django-simple-history copied to clipboard

Does not take into account 'update_fields'

Open AKanunnikov opened this issue 2 years ago • 2 comments
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:

  1. Get entity: entity_db = Entity.objects.get(pk=1)
  2. Change some fields: entity_db.some_field = 'new_value_1', entity_db.other_field = 'new_value_2'
  3. Save using the parameter 'update_fields': entity.save(update_fields=['some_field'])
  4. In Db Entity will have some_field == 'new_value_1' and other_field == 'old_value'
  5. 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]

AKanunnikov avatar Feb 15 '23 17:02 AKanunnikov

if you run save_without_historical_record, the update_fields does act as expected. (however, then lose out on the history)

jeffshek avatar Sep 06 '23 17:09 jeffshek

Faced with this weird behavior today. It would be super nice to have this fix.

Irostovsky avatar Oct 26 '23 13:10 Irostovsky