diff --git a/CHANGELOG.md b/CHANGELOG.md index 109bcdd..5c9ee82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/auditlog/models.py b/auditlog/models.py index e073c88..9a7340e 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -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 {} diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index e88c706..9a00458 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -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)