feat: add generate_rest? option to seed_generator#2591
Merged
zachdaniel merged 3 commits intoApr 16, 2026
Conversation
When `generate_rest?: false` is passed to `seed_generator/2`, only attributes explicitly provided in the attributes map (and overrides) receive generated values. Unlisted attributes use their resource-level default or nil. Raises clearly if a required attribute is missing. Defaults to `true` to preserve existing behavior.
zachdaniel
reviewed
Feb 26, 2026
zachdaniel
reviewed
Feb 26, 2026
zachdaniel
reviewed
Feb 26, 2026
Addresses review feedback on ash-project#2591: use Keyword.get(opts, :generate_rest?, true) instead of opts[:generate_rest?] == false, and place the default (generate-rest) path in the true branch of the conditional.
…lidation Addresses review feedback on ash-project#2591: generate_rest?: false validation now consults the resource's primary create action (when present). Attributes in allow_nil_input are no longer treated as required, and attributes in require_attributes are treated as required even when a default exists. Also drops two flaky `name != nil` assertions on Author — name allows nil and has a default, so nil is a valid random output that occasionally surfaces once test ordering changes.
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.
Contributor checklist
Leave anything that you believe does not apply unchecked.
Problem
seed_generatorin its tuple form{Resource, %{attrs}}generates random values for all writable, non-generated attributes, even those not listed in the attributes map. This makes it easy to accidentally introduce nondeterminism into test generators — any attribute not explicitly pinned will receive a random value, which can cause flaky tests that are difficult to trace back to the generator.Solution
Adds a
generate_rest?option toseed_generator/2. Whenfalse, only attributes explicitly listed in the attributes map (and overrides) receive generated values. Unlisted attributes receive their resource-level default ornil(ifallow_nil?). Raises with a clear message if a required attribute (allow_nil?: false, no default) is not provided, catching missing generators early.Defaults to
trueto preserve existing behavior.