fix: use mutate repo for queries with locks#234
Merged
zachdaniel merged 2 commits intoJun 3, 2026
Conversation
Contributor
|
@jsw800 code looks good, just one warning 😄 |
Contributor
Author
|
@zachdaniel updated! |
Contributor
|
🚀 Thank you for your contribution! 🚀 |
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.
https://discord.com/channels/711271361523351632/1511392095917576482/1511392095917576482
I ran onto this issue via ash_oban:
ash_oban uses
Ash.Query.lock(query, :for_update)to read records before running the trigger on the returned records. Since this is anAsh.Query, the logic here assumes that we can use the reader for this operation and calls therepofunction with:readas the argument, instead of:mutate. However, in practice we cannot useLOCK FOR UPDATEin a read-only transaction, so postgres just borks when trying to run these against a reader.This PR updates the logic so queries with locks use
:mutatewhen getting the repo. I'm open to alternative ideas for how to handle this!Contributor checklist
Leave anything that you believe does not apply unchecked.