diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f0a410..85a0b47f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ #### Fixes - Fixed logging problem related to django translation before logging ([#624](https://github.com/jazzband/django-auditlog/pull/624)) +- Fixed manuall logging when model is not registered ([#627](https://github.com/jazzband/django-auditlog/pull/627)) ## 3.0.0-beta.4 (2024-01-02) diff --git a/auditlog/models.py b/auditlog/models.py index c28cb1bc..43d2baa9 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -224,6 +224,9 @@ def _get_pk_value(self, instance): def _get_serialized_data_or_none(self, instance): from auditlog.registry import auditlog + if not auditlog.contains(instance.__class__): + return None + opts = auditlog.get_serialize_options(instance.__class__) if not opts["serialize_data"]: return None diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index b04077e7..627324f4 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -1112,6 +1112,21 @@ def test_unregister_delete(self): # Check for log entries self.assertEqual(LogEntry.objects.count(), 0, msg="There are no log entries") + def test_manual_logging(self): + obj = self.obj + obj.boolean = True + obj.save() + LogEntry.objects.log_create( + instance=obj, + action=LogEntry.Action.UPDATE, + changes="", + ) + self.assertEqual( + obj.history.filter(action=LogEntry.Action.UPDATE).count(), + 1, + msg="There is one log entry for 'UPDATE'", + ) + class RegisterModelSettingsTest(TestCase): def setUp(self):