From 336f9b2a67572245a0645d05b4665ea8199d7838 Mon Sep 17 00:00:00 2001 From: Andrew Bates Date: Mon, 31 Jul 2023 11:16:42 -0400 Subject: [PATCH] fix: Fixed signal issues (#58) * refactor: Moved signals out of class This is an attempt to troubleshoot weird signal behavior in the CI pipeline that is not reliably reproduced locally. * fix: Changing signal sender to object primary key * fix: Continuing to debug signal issues --- design_builder/contrib/ext.py | 1 + design_builder/contrib/tests/test_ext.py | 2 -- design_builder/design.py | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/design_builder/contrib/ext.py b/design_builder/contrib/ext.py index b9c312a6..5ecb0926 100644 --- a/design_builder/contrib/ext.py +++ b/design_builder/contrib/ext.py @@ -462,5 +462,6 @@ def attribute(self, value, model_instance) -> None: retval["endpoints"] = [endpoint_a, endpoint_z] endpoint_a.attributes["peering"] = model_instance endpoint_z.attributes["peering"] = model_instance + model_instance.connect(ModelInstance.POST_SAVE, BGPPeeringExtension._post_save) return retval diff --git a/design_builder/contrib/tests/test_ext.py b/design_builder/contrib/tests/test_ext.py index 215c0f38..9b3a5974 100644 --- a/design_builder/contrib/tests/test_ext.py +++ b/design_builder/contrib/tests/test_ext.py @@ -364,8 +364,6 @@ def test_creation(self): design = yaml.safe_load(design_template) object_creator = Builder(extensions=[BGPPeeringExtension]) object_creator.implement_design(design, commit=True) - for peering in Peering.objects.all(): - print("Peering:", peering) device1 = Device.objects.get(name="device1") device2 = Device.objects.get(name="device2") diff --git a/design_builder/design.py b/design_builder/design.py index 75692c23..04e9ee0e 100644 --- a/design_builder/design.py +++ b/design_builder/design.py @@ -232,7 +232,13 @@ def connect(self, signal: Signal, handler): signal: Signal to listen for. handler: Callback function """ - signal.connect(handler, self) + dispatch_id = ( + self.model_class._meta.app_label, + self.model_class._meta.model_name, + id(handler), + ) + + signal.connect(handler, self, dispatch_uid=dispatch_id) def _load_instance(self): query_filter = _map_query_values(self.filter)