diff_against
does not detect changes on deletion history type #1307
Open
Description
Describe the bug
I am comparing two records:
- The record describing when the object was created
- The record describing when the object was deleted
When I use diff_against
between these two records, the returned ModelDelta
has an empty changes
list.
To Reproduce
In [21]: person = Person.objects.create(name="Eric")
In [22]: person_pk = person.id
In [23]: person.delete()
Out[23]: (1, {'data.Person': 1})
In [24]: records = HistoricalPerson.objects.filter(id=person_pk)
In [25]: records
Out[25]: <QuerySet [<HistoricalPerson: Person object (4) as of 2024-02-14 21:13:19.406277+00:00>, <HistoricalPerson: Person object (4) as of 2024-02-14 21:13:02.534529+00:00>]>
In [26]: delta = records[0].diff_against(records[1])
In [27]: delta.__dict__
Out[27]:
{'changes': [],
'changed_fields': [],
'old_record': <HistoricalPerson: Person object (4) as of 2024-02-14 21:13:02.534529+00:00>,
'new_record': <HistoricalPerson: Person object (4) as of 2024-02-14 21:13:19.406277+00:00>}
In [28]: delta.new_record.history_type
Out[28]: '-'
Expected behavior
I expect to see that all values have changed to None
because the record no longer exists.
Environment (please complete the following information):
- OS: MacOS Sonoma 14.2.1
- Browser (if applicable): Chrome
- Django Simple History Version: 3.4.0
- Django Version: 5.0.2
- Database Version: Postgres 13
Additional context
After reading the diff_against
implementation, it appears like history_type
is not considered. Instead, changes
are computed by checking field value differences:
if old_value != current_value:
changes.append(ModelChange(field, old_value, current_value))
changed_fields.append(field)
Metadata
Assignees
Labels
No labels