Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misleading error if arguments are forgotten in Ash.Query.for_read #1551

Open
frankdugan3 opened this issue Oct 22, 2024 · 3 comments
Open

misleading error if arguments are forgotten in Ash.Query.for_read #1551

frankdugan3 opened this issue Oct 22, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@frankdugan3
Copy link
Contributor

Describe the bug

When building a read query for an action with only optional arguments, a misleading error message occurs when no arguments are passed.

iex(1)> Ash.Query.for_read(Hsm.FFL.ADRecord, :bound_book_report, actor: nil)
** (Ash.Error.Forbidden) Forbidden Error

* The domain Hsm.FFL requires that an actor is provided at all times and none was provided.
  (elixir 1.17.3) lib/process.ex:864: Process.info/2
  (ash 3.4.35) 

To Reproduce

Build a read query on any action that has only optional arguments. Not sure if the same error also happens when the action has mandatory arguments.

Expected behavior

The error should indicate that it is an action that accepts arguments, but no arguments were passed. That or maybe it should automatically insert an empty map as the arguments? 🤔

@frankdugan3 frankdugan3 added bug Something isn't working needs review labels Oct 22, 2024
@zachdaniel
Copy link
Contributor

We should probably validate inputs first? Or require that inputs is a map? That second one would be a breaking change. Anyway, definitely confusing.

@StephanH90
Copy link
Contributor

StephanH90 commented Dec 16, 2024

I couldn't reproduce this. Simply running Ash.Query.for_read(resource, :action) returns an appropriate error:

iex(3)> Ash.Query.for_read(Ash.Test.QueryTest.User, :by_id)
#Ash.Query<
  resource: Ash.Test.QueryTest.User,
  filter: #Ash.Filter<id == nil>,
  errors: [
    %Ash.Error.Query.Required{
      field: :id,
      type: :argument,
      resource: Ash.Test.QueryTest.User,
      splode: Ash.Error,
      bread_crumbs: [],
      vars: [],
      path: [],
      stacktrace: #Splode.Stacktrace<>,
      class: :invalid
    }
  ]
>

Could it be that your domain force authorization, @frankdugan3? Because in that case the error looks exactly like you described (and it makes sense to me):

iex(5)> Ash.Query.for_read(Ash.Test.QueryTest.User, :by_id)
** (Ash.Error.Forbidden) Forbidden Error

* The domain Ash.Test.Domain requires that an actor is provided at all times and none was provided.

@zachdaniel
Copy link
Contributor

If a keyword list is passed then it should be treated as an opts list, so it should see actor: nil. the check to require an actor allows nil as a value, it just requires specifying it in some way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Someday
Development

No branches or pull requests

3 participants