Child form is not automatically added when a `:union` type attribute has a `value` of `nil`

Im trying to create a Form using Form.for_update on a resource that has a :union type attribute where the value is nil:
form = AshPhoenix.Form.for_update(
%Resource{union: %Ash.Union{type: :custom, value: nil}},
forms: [auto?: true]
)

# form.forms => %{}
form = AshPhoenix.Form.for_update(
%Resource{union: %Ash.Union{type: :custom, value: nil}},
forms: [auto?: true]
)

# form.forms => %{}
With this the form.forms is empty. I would expect the forms to have a union key because I need a form to edit the union. Adding a form using AshPhoenix.Form.add_form(form, :union) adds the form, but that doesnt have the correct type set in the union, it takes the first type from the constraints it seems.
Solution:
Created a PR to resolve the issue https://github.com/ash-project/ash_phoenix/pull/417...
Jump to solution
2 Replies
Rutgerdj
RutgerdjOP4w ago
Posting here to get initial thoughts on if this is something that should work or that I'm doing something wrong. If this looks like a bug I will create a reproduction repo/test Added a comment to a commit which causes this issue: https://github.com/ash-project/ash_phoenix/commit/1c4d9ebd90d0c084abaf7ee550bf26171c20dcdd#r165509109
Solution
Rutgerdj
Rutgerdj4w ago
Created a PR to resolve the issue https://github.com/ash-project/ash_phoenix/pull/417

Did you find this page helpful?