Skip to content

fix(base_models): make the model save hook sequence atomic - #15732

Open
svader0 wants to merge 1 commit into
DefectDojo:bugfixfrom
svader0:fix/location-save-atomicity
Open

fix(base_models): make the model save hook sequence atomic#15732
svader0 wants to merge 1 commit into
DefectDojo:bugfixfrom
svader0:fix/location-save-atomicity

Conversation

@svader0

@svader0 svader0 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Consistency improvement to the shared model save path.

The pre-save hook is allowed to write related rows, so the hook, the validation and the save now run in one transaction. A save that does not complete no longer leaves part of itself behind. The savepoint is taken only for models that override the hook, so the import query-count contract is unchanged.

Adds a regression test. No functional change for a save that succeeds.

pre_save_logic() is allowed to write related rows, and the base model ran it
before full_clean(). A save rejected by validation therefore kept the hook's
writes while its own row was never updated, so the two disagreed from then on.
Nothing rolled that back: the default database does not use ATOMIC_REQUESTS,
and the callers that catch the error cannot undo a write another model made.

Wrap the hook, the validation and the save in one transaction. The savepoint is
taken only when a subclass overrides pre_save_logic, so the models that do not
(Finding among them) keep their savepoint-free save and the import query-count
contract is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant