** (Ash.Error.Invalid) Invalid Error * No such field name for resource

I am creating an admin app with data similar to the Tunez app from the Ash book from PragPro.
I want to query the artists by name sorted by name.

Using the tunez code, I am able to query via:

 Tunez.Music.search_artists!("a", query: [sort_input: "name"])

When querying with my app via:

Tuneshg.Music.search_artists!("a", query: [sort_input: "name"])

I get:

** (Ash.Error.Invalid) 
Invalid Error

* No such field name for resource Tuneshg.Music.Artist
    at sort
  (ash 3.4.55) lib/ash/error/query/no_such_field.ex:5: Ash.Error.Query.NoSuchField.exception/1
  (ash 3.4.55) lib/ash/sort/sort.ex:210: Ash.Sort.parse_sort/3
  (ash 3.4.55) lib/ash/sort/sort.ex:131: anonymous fn/4 in Ash.Sort.parse_input/3
  (elixir 1.18.1) lib/enum.ex:4964: Enumerable.List.reduce/3
  (elixir 1.18.1) lib/enum.ex:2600: Enum.reduce_while/3
  (ash 3.4.55) lib/ash/sort/sort.ex:130: Ash.Sort.parse_input/3
  (ash 3.4.55) lib/ash/query/query.ex:323: Ash.Query.sort_input/3
  (elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
  (tuneshg 0.1.0) deps/ash/lib/ash/code_interface.ex:676: Tuneshg.Music.search_artists!/3
  (elixir 1.18.1) src/elixir.erl:386: :elixir.eval_external_handler/3
  (stdlib 6.2) erl_eval.erl:919: :erl_eval.do_apply/7
  (elixir 1.18.1) src/elixir.erl:364: :elixir.eval_forms/4
  (elixir 1.18.1) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
  (iex 1.18.1) lib/iex/evaluator.ex:336: IEx.Evaluator.eval_and_inspect/3
  (iex 1.18.1) lib/iex/evaluator.ex:310: IEx.Evaluator.eval_and_inspect_parsed/3
  (iex 1.18.1) lib/iex/evaluator.ex:299: IEx.Evaluator.parse_eval_inspect/4
  (iex 1.18.1) lib/iex/evaluator.ex:189: IEx.Evaluator.loop/1
  (iex 1.18.1) lib/iex/evaluator.ex:34: IEx.Evaluator.init/5
  (stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
    (ash 3.4.55) lib/ash/error/invalid.ex:3: Ash.Error.Invalid.exception/1
    (ash 3.4.55) /Volumes/Quizzlab/Projects/tuneshg/deps/splode/lib/splode.ex:264: Ash.Error.to_class/2
    (ash 3.4.55) lib/ash/error/error.ex:108: Ash.Error.to_error_class/2
    (ash 3.4.55) lib/ash/actions/read/read.ex:29: Ash.Actions.Read.run/3
    (ash 3.4.55) lib/ash.ex:2008: Ash.read/2
    (ash 3.4.55) lib/ash.ex:1966: Ash.read!/2
    iex:4: (file)

The artist search action, and attributes are the same
The album define :search_artists are the same.

What could be the reason for the Ash.Error?
How can I evaluate what field is missing?

Thanks for your reply, Heiko

The name attribute needs to be marked as public? true :slight_smile:

As sort_input is intended for use with untrusted input, such as from a query string, you need to explicitly allow each field that you allow to be sorted on, by making them public.

Oh my.

Thank you again Rebecca.
Again you are right :sweat_smile:

And you are faster than lightning!

It works and now my admin tool for Artists and Albums is complete.

I promise not to ask anything today :innocent:

Have a nice Saturday.

Best wishes from Heiko

1 Like