Fix LogEntry.changes_dict() to return {} when json.loads() returns None (#472)

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
This commit is contained in:
Thomas Steen Rasmussen 2022-12-13 21:35:31 +01:00 committed by GitHub
parent cd1ba3d01b
commit 27f57a53ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View file

@ -2,6 +2,10 @@
## Next Release
#### Fixes
- fix: Make sure `LogEntry.changes_dict()` returns an empty dict instead of `None` when `json.loads()` returns `None`. ([#472](https://github.com/jazzband/django-auditlog/pull/472))
## 2.2.1 (2022-11-28)
#### Fixes

View file

@ -387,7 +387,7 @@ class LogEntry(models.Model):
:return: The changes recorded in this log entry as a dictionary object.
"""
try:
return json.loads(self.changes)
return json.loads(self.changes) or {}
except ValueError:
return {}

View file

@ -1841,6 +1841,7 @@ class TestAccessLog(TestCase):
log_entry.action, LogEntry.Action.ACCESS, msg="Action is 'ACCESS'"
)
self.assertEqual(log_entry.changes, "null")
self.assertEqual(log_entry.changes_dict, {})
@override_settings(AUDITLOG_DISABLE_ON_RAW_SAVE=True)