fix: support atomic-only changes in bulk_create#2635
Merged
zachdaniel merged 2 commits intoash-project:mainfrom Mar 13, 2026
Merged
fix: support atomic-only changes in bulk_create#2635zachdaniel merged 2 commits intoash-project:mainfrom
zachdaniel merged 2 commits intoash-project:mainfrom
Conversation
The `batch_change` function in `create/bulk.ex` only called `change/3` on change modules, never checking `module.atomic?()` or calling `run_atomic_change`. This meant `atomic_set` expressions were evaluated in-memory rather than being passed to the database as SQL. The update bulk path (`update/bulk.ex`) already had the correct three-branch cond: batch_change > change > atomic. This commit adds the same `module.atomic?()` branch to the create bulk path. Without this fix, `atomic_set` with expressions like SQL fragments would silently produce incorrect values when used with `Ash.bulk_create!`.
Add tests for change modules that only implement atomic/3 (no change/3
or batch_change/3) and for the {:not_atomic, reason} error path.
Extract batch_atomic_change/6 helper to deduplicate identical blocks.
zachdaniel
approved these changes
Mar 13, 2026
Contributor
|
This is cool, I'm actually not even sure if atomic only changes properly work in creates? I added support for atomics in creates but I don't recall how I handled that 🤔 |
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.
Summary
batch_changeinAsh.Actions.Create.Bulkto support change modules that only implementatomic/3(nochange/3orbatch_change/3)batch_changebecause the fallback always calledchange/3, which doesn't exist on atomic-only modulescond-based dispatch (has_batch_change?→has_change?→atomic?) replacing the old 2-branchif/elsebatch_atomic_change/6helper to avoid duplication across the templated and non-templated code pathsTest plan
atomic_setwith per-record arguments in bulk_create (multi-record and single-record)change/3) exercising the newatomic?fallback path{:not_atomic, reason}error handling in bulk contextmix compile --warnings-as-errorscleanmix format --check-formattedclean