Closed
Conversation
944eaa1 to
a5e99ab
Compare
Add rollback_on_error?: false to bulk_update and bulk_destroy calls. This ensures after_transaction callbacks are invoked even when errors occur (e.g., database constraint violations). Previously, errors caused immediate rollback that skipped after_transaction.
Add test resources (AfterTransactionEts, AfterTransactionMnesia) and tests verifying after_transaction callbacks run on both success and error cases for create, update, and destroy mutations. Mnesia tests use real transactions to verify the fix works with actual transaction semantics.
6b761b7 to
3a3fbf6
Compare
3a3fbf6 to
05002dd
Compare
Contributor
Author
|
This has another issue |
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.
Fixes after_transaction callbacks not being invoked when errors occur during GraphQL mutations.
Background
Ash recently added support for after_transaction hooks in the atomic path for bulk operations. However, when
rollback_on_error? is true (the default) and an error occurs, Ash.DataLayer.rollback throws to exit the transaction
immediately. This unwinds the call stack and bypasses process_results where after_transaction hooks would normally
be executed—the changeset context needed to run the hooks is effectively abandoned.
Since GraphQL mutations use bulk operations with the atomic strategy, after_transaction callbacks weren't being
called when errors occurred (e.g., database constraint violations).
Solution
Add rollback_on_error?: false to bulk_update and bulk_destroy calls in the resolver. This allows the transaction to
complete normally (with errors collected) so that process_results runs and after_transaction callbacks are invoked
with the error result.
Note: Setting rollback_on_error?: false is safe here because ash_graphql mutations only operate on a single record
at a time—there's no risk of partial updates across multiple records.
The last commit should also fix the compile warnings in ci
Contributor checklist