-
Notifications
You must be signed in to change notification settings - Fork 430
Open
Description
I think there is a bug due to the recently introduced setting AUDITLOG_STORE_JSON_CHANGES
and the way it works. When creating a new record, the changes
field gets populated by fields that did not change.
Environment
Python: 3.12
django-auditlog: 3.2.1
Model
class TestModel(Model):
text = models.CharField(default="abc")
time = models.TimeField(null=True, blank=True)
Steps
- Set
AUDITLOG_STORE_JSON_CHANGES
toFalse
. - Create and save a new instance of the model with
text="abc", time=None
. auditlog.receivers.log_create
callsauditlog.receivers._create_log_entry
.auditlog.diff.model_instance_diff
gets called withold
beingNone
andnew
being the new model instance.use_json_for_changes
isFalse
.- When
old_value
andnew_value
get calculated for the fieldtime
, their values areNone
and"None"
, which means that they do not match and the fieldtime
gets added to thediff
variable as("None", "None")
, and then laterLogEntry
gets created withchanges
containing the same.
The same problem would happen for the DateField
but not for the DateTimeField
which has its own handling in auditlog.diff.get_field_value
. The handling of that method's return value is inconsistent. Sometimes smart_str
is applied, sometimes not.
2ykwang
Metadata
Metadata
Assignees
Labels
No labels