From a56d0e6f784f3d0e1107f41c8c7a3f2423686c14 Mon Sep 17 00:00:00 2001 From: Rahul Prasad Date: Wed, 21 Sep 2022 12:23:10 +0530 Subject: [PATCH] added fix for OneToOneRel error happening in case of Polymorphic model (#429) --- CHANGELOG.md | 1 + auditlog/diff.py | 6 +++++- auditlog_tests/tests.py | 1 - 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66afb7e..b84bfc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - fix: Display `created` timestamp in server timezone ([#404](https://github.com/jazzband/django-auditlog/pull/404)) - fix: Handle port in `remote_addr` ([#417](https://github.com/jazzband/django-auditlog/pull/417)) +- fix: Handle the error with AttributeError: 'OneToOneRel' error occur during a `PolymorphicModel` has relation with other models ([#429](https://github.com/jazzband/django-auditlog/pull/429)) ## 2.1.1 (2022-07-27) diff --git a/auditlog/diff.py b/auditlog/diff.py index 83cd1aa..74bd9a0 100644 --- a/auditlog/diff.py +++ b/auditlog/diff.py @@ -70,7 +70,11 @@ def get_field_value(obj, field): else: value = smart_str(getattr(obj, field.name, None)) except ObjectDoesNotExist: - value = field.default if field.default is not NOT_PROVIDED else None + value = ( + field.default + if getattr(field, "default", NOT_PROVIDED) is not NOT_PROVIDED + else None + ) return value diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index 5751f4f..0adb710 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -1145,7 +1145,6 @@ class ChoicesFieldModelTest(TestCase): ) def test_changes_display_dict_single_choice(self): - self.assertEqual( self.obj.history.latest().changes_display_dict["status"][1], "Red",