Description
Describe the bug
The update_change_reason
method in utils.py
fails to update change reason in case any field is nullable in a model or is set to default to None
. This could be due to the way django handles null values, as direct comparison to None
is not allowed when filtering.
To Reproduce
Steps to reproduce the behavior:
- Create a model with any nullable field or a field that defaults to
None
and enable historical records. - Try to use the
update_change_reason
on an instance of the model.
Expected behavior
The update_change_reason
should handle models with nullable fields/fields with default set to None gracefully by applying the correct filter query for fetching historical records.
Environment (please complete the following information):
- OS: Win 11 24H2
- Django Simple History Version: 3.8.0
- Django Version: 5.0.11
- Database Version: PostgreSQL 16.8
Additional context
In the provided screenshot you can see, the History Attrs
logged from within the update_change_reason
method indicating that it is using the wrong filter query for filtering/matching null value, instead of field=None
it should have been field__isnull
=True, which prevented the historical record from showing up causing an exception.