From 4228459de844fad1a032cd60fd8ada1dcd50b6ad Mon Sep 17 00:00:00 2001 From: Jeff Kala Date: Thu, 22 Feb 2024 22:21:30 -0600 Subject: [PATCH] implement objectchange log excludes for object_data_v2 data as well --- nautobot_golden_config/models.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nautobot_golden_config/models.py b/nautobot_golden_config/models.py index e9ccd9b6..a9239427 100644 --- a/nautobot_golden_config/models.py +++ b/nautobot_golden_config/models.py @@ -314,14 +314,18 @@ def to_objectchange( self, action, *, related_object=None, object_data_extra=None, object_data_exclude=None ): # pylint: disable=arguments-differ """Remove actual and intended configuration from changelog.""" + fields_to_exclude = ["actual", "intended"] if not object_data_exclude: - object_data_exclude = ["actual", "intended"] + object_data_exclude = fields_to_exclude + data_v2 = serialize_object_v2(self) + for field in fields_to_exclude: + data_v2.pop(field) return ObjectChange( changed_object=self, object_repr=str(self), action=action, object_data=serialize_object(self, extra=object_data_extra, exclude=object_data_exclude), - object_data_v2=serialize_object_v2(self), + object_data_v2=data_v2, related_object=related_object, ) @@ -413,14 +417,18 @@ def to_objectchange( self, action, *, related_object=None, object_data_extra=None, object_data_exclude=None ): # pylint: disable=arguments-differ """Remove actual and intended configuration from changelog.""" + fields_to_exclude = ["backup_config", "intended_config", "compliance_config"] if not object_data_exclude: - object_data_exclude = ["backup_config", "intended_config", "compliance_config"] + object_data_exclude = fields_to_exclude + data_v2 = serialize_object_v2(self) + for field in fields_to_exclude: + data_v2.pop(field) return ObjectChange( changed_object=self, object_repr=str(self), action=action, object_data=serialize_object(self, extra=object_data_extra, exclude=object_data_exclude), - object_data_v2=serialize_object_v2(self), + object_data_v2=data_v2, related_object=related_object, )