-
Notifications
You must be signed in to change notification settings - Fork 437
Closed
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_CHANGEStoFalse. - Create and save a new instance of the model with
text="abc", time=None. auditlog.receivers.log_createcallsauditlog.receivers._create_log_entry.auditlog.diff.model_instance_diffgets called witholdbeingNoneandnewbeing the new model instance.use_json_for_changesisFalse.- When
old_valueandnew_valueget calculated for the fieldtime, their values areNoneand"None", which means that they do not match and the fieldtimegets added to thediffvariable as("None", "None"), and then laterLogEntrygets created withchangescontaining 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