Compare commits

..

4 Commits

Author SHA1 Message Date
Arthur
7b9ab87e38 cleanup 2026-04-10 12:04:48 -07:00
Arthur
90255a268f cleanup 2026-04-10 11:57:49 -07:00
Arthur
8418809344 #21879 - Add post_raw_create signal hook 2026-04-10 11:31:56 -07:00
Arthur
b39e1c73c1 #21879 - Add post_raw_create signal hook 2026-04-10 11:28:10 -07:00
2 changed files with 29 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ from django.dispatch import receiver
from dcim.choices import CableEndChoices, LinkStatusChoices
from ipam.models import Prefix
from netbox.signals import post_raw_create
from virtualization.models import Cluster, VMInterface
from wireless.models import WirelessLAN
@@ -166,6 +167,27 @@ def retrace_cable_paths(instance, **kwargs):
cablepath.retrace()
@receiver(post_raw_create, sender=Cable)
def retrace_cable_paths_after_raw_create(sender, pks, **kwargs):
"""
When Cables are created via a raw save, the normal Cable.save() path is bypassed,
so trace_paths is never sent. Retrace paths for all newly created cables.
Callers must only send this signal after all CableTerminations for the given cables
have been applied. If a cable has no terminations, update_connected_endpoints will
find empty termination lists and skip path creation — so this is safe to call even
if terminations are absent, but path tracing will have no effect.
Note: raw=False (the default) is intentional here — we explicitly want
update_connected_endpoints to run, unlike during fixture loading (raw=True).
"""
logger = logging.getLogger('netbox.dcim.cable')
for cable in Cable.objects.filter(pk__in=pks):
cable._terminations_modified = True
trace_paths.send(Cable, instance=cable, created=True)
logger.debug(f"Retraced cable paths for Cable {cable.pk}")
@receiver((post_delete, post_save), sender=PortMapping)
def update_passthrough_port_paths(instance, **kwargs):
"""

View File

@@ -2,3 +2,10 @@ from django.dispatch import Signal
# Signals that a model has completed its clean() method
post_clean = Signal()
# Sent after objects of a given model are created via raw save.
# Expected call signature: post_raw_create.send(sender=MyModel, pks=[...])
# Provides: pks (list) - PKs of the newly created objects.
# Callers must ensure all related objects (e.g. M2M, dependent rows) are in place
# before sending, as receivers may query related data to perform post-create work.
post_raw_create = Signal()