From 56433cf85520edee9cf0d440bfeb82524eac7fc7 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 4 Aug 2022 10:42:44 -0400 Subject: [PATCH] Fix denormalization logic to be compatible with loading fixture data --- netbox/netbox/denormalized.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox/netbox/denormalized.py b/netbox/netbox/denormalized.py index 5808acddc..cd4a869d2 100644 --- a/netbox/netbox/denormalized.py +++ b/netbox/netbox/denormalized.py @@ -33,6 +33,10 @@ def update_denormalized_fields(sender, instance, created, raw, **kwargs): """ Check if the sender has denormalized fields registered, and update them as necessary. """ + def _get_field_value(instance, field_name): + field = instance._meta.get_field(field_name) + return field.value_from_object(instance) + # Skip for new objects or those being populated from raw data if created or raw: return @@ -45,7 +49,7 @@ def update_denormalized_fields(sender, instance, created, raw, **kwargs): } update_params = { # Map the denormalized field names to the instance's values - denorm: getattr(instance, origin) for denorm, origin in mappings.items() + denorm: _get_field_value(instance, origin) for denorm, origin in mappings.items() } # TODO: Improve efficiency here by placing conditions on the query?