feat: add generate_rest? option to seed_generator#2591
Draft
robesris wants to merge 1 commit intoash-project:mainfrom
Draft
feat: add generate_rest? option to seed_generator#2591robesris wants to merge 1 commit intoash-project:mainfrom
robesris wants to merge 1 commit intoash-project:mainfrom
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
| ) | ||
| merged = Map.merge(attributes, Map.new(opts[:overrides] || %{})) | ||
|
|
||
| if opts[:generate_rest?] == false do |
Contributor
There was a problem hiding this comment.
I'd flip the conditional, and use if Keyword.get(opts, :generate_rest?, true) do to make the access default to true.
zachdaniel
reviewed
Feb 26, 2026
| ) | ||
| merged = Map.merge(attributes, Map.new(opts[:overrides] || %{})) | ||
|
|
||
| if opts[:generate_rest?] == false do |
zachdaniel
reviewed
Feb 26, 2026
| default = | ||
| if action_type == :create, do: attribute.default, else: attribute.update_default | ||
|
|
||
| if !attribute.allow_nil? && is_nil(default) && !Map.has_key?(generators, attribute.name) do |
Contributor
There was a problem hiding this comment.
There is a bit more to check here. If the attribute is a create or update action, then we have to check if it's in allow_nil_input (overrides required attributes) or require_attributes (makes an input required that would not normally be required). Otherwise this looks great!
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.