Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff_against does not detect changes on deletion history type #1307

Open
euriostigue opened this issue Feb 14, 2024 · 0 comments · May be fixed by #1312
Open

diff_against does not detect changes on deletion history type #1307

euriostigue opened this issue Feb 14, 2024 · 0 comments · May be fixed by #1312

Comments

@euriostigue
Copy link

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)
@euriostigue euriostigue linked a pull request Feb 20, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant