Skip to content

fix: Skip embed form standalone validation#473

Closed
sevenseacat wants to merge 2 commits into
mainfrom
fix/skip-embed-form-standalone-validation
Closed

fix: Skip embed form standalone validation#473
sevenseacat wants to merge 2 commits into
mainfrom
fix/skip-embed-form-standalone-validation

Conversation

@sevenseacat

@sevenseacat sevenseacat commented May 13, 2026

Copy link
Copy Markdown
Contributor

As discussed on Discord, there's a bit of a gap in how AshPhoenix treats forms for embedded resources vs. related resources - embedded resources really shouldn't be validated separately, their validation is done via the parent form.

The edge cases is for union types - there are existing tests verifying the expected behaviour for unions, and they continue to pass.

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

sevenseacat and others added 2 commits May 12, 2026 22:12
Nested forms backed by an embedded attribute/argument were validated
twice: once against the embed's own create/update action, and again
inline when the parent action cast the merged params. The standalone
pass bypasses parent-level logic (e.g. a `cast_input/2` override on
the embed that collapses blank input to `nil`), so an all-blank embed
sub-form produced spurious "is required" errors even when the parent
would have accepted the value as nil.

After validating, clear `source.errors` and mark the source valid for
forms with `embed?: true`. `carry_over_errors/2` replays any real
errors the parent's validation surfaces with a matching path. Forms
with `transform_params` set are skipped — unions rewrite params into
an `%Ash.Union{}` before handing them up, so their standalone
validation is the only line of defense.
`clear_embed_source_errors/2` used `!opts[:transform_params]` to detect
union sub-forms. `transform_params` is also a public form option, so a
caller setting it on a non-union embed (undocumented but reachable)
would silently disable the exemption. Set `union?: true` in `unions/3`
and check that instead.
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.

1 participant