Skip to content

fixes for embedded resources within unions#2676

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
jsw800:fix-embedded-resource-unions
Apr 15, 2026
Merged

fixes for embedded resources within unions#2676
zachdaniel merged 1 commit intoash-project:mainfrom
jsw800:fix-embedded-resource-unions

Conversation

@jsw800
Copy link
Copy Markdown
Contributor

@jsw800 jsw800 commented Apr 14, 2026

These changes fix a few issues that I ran into with unions of embedded resources.

What I'm trying to do is:

  • a union
  • with constraint storage: :map_with_tag
  • The individual types are embedded resources
  • Some of these embedded resources' attributes include a source field that remaps them from what's in the DB (the DB versions are camel case because of bad past decisions)
  • There are field policies on some of the embedded resource fields since they should not be visible to everyone

I've run into a few issues doing this. I worked with opencode to get to some solutions here. I'm struggling to put together good test reproductions since this is kind of a niche use case and I've mostly been testing it against my own codebase.

The issues themselves are:

  • loads of embedded resources inside unions were being bypassed by the def load(unions, [], _, _), do: {:ok, unions} function head
    • the fix for this was to remove that function head and simply default the load variable to [] in the main function head
  • the __union_tag__ property was not being properly included in a few code paths that handle updates, resulting in errors about No such input type for action <MyAction> (type is my tag key)
    • the fix was to include __union_tag__ in the constraints in those code paths
  • field policies were not being properly applied to the fields in the embedded resources
    • the fix was the changes in read.ex to the cleanup_field_auth function. To be transparent, I understand these changes less well than I do the other two—opencode is mostly responsible for these. I would appreciate a bit of a closer look at this section from someone with a much closer understanding of this module's code.

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

@zachdaniel zachdaniel merged commit afebe88 into ash-project:main Apr 15, 2026
45 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

Seems reasonable to me 😄

🚀 Thank you for your contribution! 🚀

@jsw800 jsw800 deleted the fix-embedded-resource-unions branch April 15, 2026 15:39
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.

2 participants