Skip to content

Commit

Permalink
fix: Changing signal sender to object primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
abates committed Jul 31, 2023
1 parent ae0c42e commit 2bf9e35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions design_builder/contrib/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,9 @@ def __init__(self, object_creator: Builder):
)

@staticmethod
def _post_save(sender, **kwargs) -> None:
peering_instance: ModelInstance = sender
endpoint_a = peering_instance.instance.endpoint_a
endpoint_z = peering_instance.instance.endpoint_z
def _post_save(model_instance: ModelInstance, **kwargs) -> None:
endpoint_a = model_instance.instance.endpoint_a
endpoint_z = model_instance.instance.endpoint_z
endpoint_a.peer, endpoint_z.peer = endpoint_z, endpoint_a
endpoint_a.save()
endpoint_z.save()
Expand Down
6 changes: 3 additions & 3 deletions design_builder/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def connect(self, signal: Signal, handler):
signal: Signal to listen for.
handler: Callback function
"""
signal.connect(handler, self)
signal.connect(handler, self.instance.pk)

def _load_instance(self):
query_filter = _map_query_values(self.filter)
Expand Down Expand Up @@ -310,7 +310,7 @@ def save(self):
# ensure that parent instances have been saved and
# assigned a primary key
self._update_fields()
INSTANCE_PRE_SAVE.send(sender=self)
INSTANCE_PRE_SAVE.send(sender=self.instance.pk, model_instance=self)
try:
self.instance.full_clean()
self.instance.save()
Expand Down Expand Up @@ -339,7 +339,7 @@ def save(self):
self.instance.refresh_from_db()

field.set_value(related_object.instance)
INSTANCE_POST_SAVE.send(sender=self)
INSTANCE_POST_SAVE.send(sender=self.instance.pk, model_instance=self)

def set_custom_field(self, field, value):
"""Sets a value for a custom field."""
Expand Down

0 comments on commit 2bf9e35

Please sign in to comment.