Skip to content

manage_relationship validation returns only one error for multiple invalid related records #2665

@tunchamroeun

Description

@tunchamroeun

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Versions

erlang 28.1
elixir 1.19.0-otp-28
pipx 1.8.0

Operating system

MacOS

Current Behavior

manage_relationship validation returns only one error for multiple invalid related records

%Ash.Error.Invalid{
               errors: [
                 %Ash.Error.Changes.Required{
                   field: :required_attribute,
                   type: :attribute,
                   path: [:other_resources, 0]
                 },
               ]
             }

Currently, it returns only one error, even though there are two invalid related records in other_resources.

The expectation is that each invalid related item should produce its own error with the correct path, instead of collapsing them into a single error.

Reproduction

Reproduction Repo

https://github.com/tunchamroeun/ash

Run

mix test test/manage_relationship_test.exs

Reproduction test:

Expected Behavior

Given this input:

input = %{
               name: "Test Parent Resource",
               other_resources: [
                 %{
                   required_attribute: nil,
                   order: 0
                 },
                 %{
                   required_attribute: nil,
                   order: 1
                 }
               ]
             }

It should return two validation errors, one for each invalid related record:

%Ash.Error.Invalid{
               errors: [
                 %Ash.Error.Changes.Required{
                   field: :required_attribute,
                   type: :attribute,
                   path: [:other_resources, 0]
                 },
                 %Ash.Error.Changes.Required{
                   field: :required_attribute,
                   type: :attribute,
                   path: [:other_resources, 1]
                 }
               ]
             }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions