fix(base_models): make the model save hook sequence atomic - #15732
Open
svader0 wants to merge 1 commit into
Open
fix(base_models): make the model save hook sequence atomic#15732svader0 wants to merge 1 commit into
svader0 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.