Add post_raw_create signal hook for running post-save logic after raw object creation#21880
Add post_raw_create signal hook for running post-save logic after raw object creation#21880arthanson wants to merge 9 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
jeremystretch
left a comment
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
|
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). |
|
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. |
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.