From 632b1c6b04efa494d97a8974b98a37492a9b0249 Mon Sep 17 00:00:00 2001 From: Lukas Graf Date: Mon, 24 Nov 2025 19:38:01 +0100 Subject: [PATCH] Add failing test for diffing polymorphic model instances. --- auditlog_tests/test_app/models.py | 1 + auditlog_tests/tests.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/auditlog_tests/test_app/models.py b/auditlog_tests/test_app/models.py index e996a25..0ee7852 100644 --- a/auditlog_tests/test_app/models.py +++ b/auditlog_tests/test_app/models.py @@ -487,6 +487,7 @@ auditlog.register(AltPrimaryKeyModel) auditlog.register(UUIDPrimaryKeyModel) auditlog.register(ModelPrimaryKeyModel) auditlog.register(ProxyModel) +auditlog.register(RelatedModelParent) auditlog.register(RelatedModel) auditlog.register(ManyRelatedModel) auditlog.register(ManyRelatedModel.recursive.through) diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index f12ef9d..b446880 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -47,6 +47,7 @@ from test_app.models import ( NullableJSONModel, ProxyModel, RelatedModel, + RelatedModelParent, ReusableThroughRelatedModel, SecretM2MModel, SecretRelatedModel, @@ -2131,6 +2132,27 @@ class ModelInstanceDiffTest(TestCase): model_instance_diff(simple2, simple1) model_instance_diff(simple1, simple2) + def test_diff_polymorphic_models(self): + """No error is raised when comparing parent/child for polymorphic models.""" + + # This tests that when a polymorphic model is compared to its parent, + # no FieldDoesNotExist errors are raised because those fields don't exist + # on the parent model. + + # relation target + simple = SimpleModel() + simple.save() + + # the parent model + related_parent = RelatedModelParent() + related_parent.save() + + # the child model, with some fields that don't exist on the parent + related = RelatedModel(related=simple, one_to_one=simple) + related.save() + + model_instance_diff(related, related_parent) + def test_object_repr_related_deleted(self): """No error is raised when __str__() loads a related object that has been deleted.""" simple = SimpleModel()