Transaction-safe ObjectRole creation #281
Merged
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.
I got a report from the UI that doing multiple assignments concurrently would give server errors inconsistently. It actually made complete sense that this would be the case, and I developed a reproducer that identifies the obvious suspect.
We can't put this reproducer in a test, because the test works inside of a transaction. Nested transactions (in postgres/django) do not work the same as independent transactions (auto-commit outside the context). Because of that, these are ran in 2 different terminal tabs.
Reproducer, these lines all have to happen sequentially. You're flipping between 2 tabs. shell_plus works best.
Once you run the final command, "process 2" hits this error:
I developed a test that uses mock to approximate this, although I would not trust such a test to fully verify the fix. Like, it's non-obvious that the
.get
after theIntegrityError
would actually be able to fetch the object. I re-ran the above reproducer and every worked and I'm fairly satisfied with that.Internal AAP-22518