Skip to content

fix: use mutate repo for queries with locks#234

Merged
zachdaniel merged 2 commits into
ash-project:mainfrom
jsw800:fix/use-mutate-for-locked-queries
Jun 3, 2026
Merged

fix: use mutate repo for queries with locks#234
zachdaniel merged 2 commits into
ash-project:mainfrom
jsw800:fix/use-mutate-for-locked-queries

Conversation

@jsw800
Copy link
Copy Markdown
Contributor

@jsw800 jsw800 commented Jun 2, 2026

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 an Ash.Query, the logic here assumes that we can use the reader for this operation and calls the repo function with :read as the argument, instead of :mutate. However, in practice we cannot use LOCK FOR UPDATE in 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 :mutate when 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.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@zachdaniel
Copy link
Copy Markdown
Contributor

@jsw800 code looks good, just one warning 😄

@jsw800
Copy link
Copy Markdown
Contributor Author

jsw800 commented Jun 3, 2026

@zachdaniel updated!

@zachdaniel zachdaniel merged commit c160a6f into ash-project:main Jun 3, 2026
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

@jsw800 jsw800 deleted the fix/use-mutate-for-locked-queries branch June 3, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants