Skip to content

Add post_raw_create signal hook for running post-save logic after raw object creation#21880

Open
arthanson wants to merge 9 commits into
mainfrom
post-raw-signal
Open

Add post_raw_create signal hook for running post-save logic after raw object creation#21880
arthanson wants to merge 9 commits into
mainfrom
post-raw-signal

Conversation

@arthanson

@arthanson arthanson commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes: #21879

Triggers cable path retracing after a Cable is created outside the normal save() path (e.g., via bulk_create()). Callers must dispatch Django's built-in post_save signal with post_raw_create=True after all CableTermination records are in place. Without the flag the handler is a no-op, so normal saves are unaffected.

We need a new parameter on the signal-handler instead of using raw=True. Using a handler gated on raw=True would fire at exactly the wrong time. Django sets raw=True during loaddata and fixture imports - scenarios where the database is being populated in dependency order and CableTermination records for a given cable may not exist yet.

@netbox-community netbox-community deleted a comment from claude Bot Apr 10, 2026
@arthanson

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@arthanson

This comment was marked as outdated.

@arthanson arthanson requested a review from jeremystretch April 10, 2026 19:05

@jeremystretch jeremystretch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the justification for introducing a new signal. Isn't this already possible using Django's stock post_save signal by filtering on the raw argument? I understand that the proposed implementation utilizes a list of primary keys, but it's just operating on a for loop that isn't substantially different from call the receiver function one per object. I'd much rather leverage the existing signal if feasible.

@arthanson arthanson requested a review from jeremystretch April 15, 2026 15:30
Comment thread netbox/dcim/signals.py Outdated
@jeremystretch jeremystretch self-requested a review April 16, 2026 12:48
Comment thread netbox/dcim/signals.py
recalculated. Callers should fire post_save with post_raw_create=True after
all CableTerminations are in place.
"""
post_raw_create = kwargs.get('post_raw_create', False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my earlier feedback wasn't clear. I don't think we need a custom argument at all. post_save already passes created and raw booleans: It should suffice to check whether both are true.

@arthanson

Copy link
Copy Markdown
Collaborator Author

See comment at top: "We need a new parameter on the signal-handler instead of using raw=True. Using a handler gated on raw=True would fire at exactly the wrong time. Django sets raw=True during loaddata and fixture imports - scenarios where the database is being populated in dependency order and CableTermination records for a given cable may not exist yet."

Since we want this not just for cable but potentially use similar if another model in the future has something similar I'm very leery of changing the meaning of the signal handler raw=True as that has a different meaning in Django and we could have side-effects to loaddata (among others, not sure what all Django might use it for).

@arthanson arthanson requested a review from jeremystretch April 20, 2026 16:02
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken.

@github-actions github-actions Bot added the pending closure Requires immediate attention to avoid being closed for inactivity label May 21, 2026
@jeremystretch jeremystretch removed the pending closure Requires immediate attention to avoid being closed for inactivity label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add post_raw_create signal hook for models requiring post-save logic after raw object creation

2 participants