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

Calling a code interface create with keyword as input instead of a map gives a non-helpful failure message. #992

Open
jimsynz opened this issue Apr 8, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jimsynz
Copy link
Contributor

jimsynz commented Apr 8, 2024

Describe the bug

iex(2)> MyApp.MyDomain.SchoolYear.create([name: "2024", start_date: Date.utc_today(), end_date: Date.utc_today()], actor: actor, tenant: "tenant")
** (Ash.Error.Unknown) Unknown Error

* ** (ArgumentError) `nil` is not a Spark DSL module.

  nil.persisted(:data_layer)
  (spark 1.1.54) lib/spark/dsl/extension.ex:136: Spark.Dsl.Extension.persisted!/3
  (ash 2.18.2) lib/ash/filter/filter.ex:3428: Ash.Filter.do_hydrate_refs/2
  (ash 2.18.2) lib/ash/policy/check/expression.ex:3: Ash.Policy.Check.Expression.try_eval/2
  (ash 2.18.2) lib/ash/policy/check/expression.ex:3: Ash.Policy.Check.Expression.try_strict_check/3
  (ash 2.18.2) lib/ash/policy/policy.ex:165: Ash.Policy.Policy.fetch_or_strict_check_fact/2
  (ash 2.18.2) lib/ash/policy/policy.ex:482: Ash.Policy.Policy.compile_policy_expression/2
  (ash 2.18.2) lib/ash/policy/policy.ex:321: Ash.Policy.Policy.compile_policy_expression/2
  (ash 2.18.2) lib/ash/policy/policy.ex:68: Ash.Policy.Policy.build_requirements_expression/2
  (ash 2.18.2) lib/ash/policy/policy.ex:26: Ash.Policy.Policy.solve/1
  (ash 2.18.2) lib/ash/policy/checker.ex:83: Ash.Policy.Checker.strict_check_scenarios/1
  (ash 2.18.2) lib/ash/policy/authorizer/authorizer.ex:1285: Ash.Policy.Authorizer.strict_check_result/2
  (ash 2.18.2) lib/ash/policy/authorizer/authorizer.ex:482: Ash.Policy.Authorizer.strict_check/2
  (ash 2.18.2) lib/ash/api/api.ex:938: anonymous fn/5 in Ash.Api.run_check/4
  (elixir 1.16.1) lib/enum.ex:4842: Enumerable.List.reduce/3
  (elixir 1.16.1) lib/enum.ex:2582: Enum.reduce_while/3
  (ash 2.18.2) lib/ash/api/api.ex:935: Ash.Api.run_check/4
  (ash 2.18.2) lib/ash/api/api.ex:812: Ash.Api.can/4
  (ash 2.18.2) lib/ash/actions/create/create.ex:138: Ash.Actions.Create.authorize/3
  (ash 2.18.2) lib/ash/actions/create/create.ex:106: Ash.Actions.Create.do_run/4
    nil.persisted(:data_layer)
    (spark 1.1.54) lib/spark/dsl/extension.ex:136: Spark.Dsl.Extension.persisted!/3
    (ash 2.18.2) lib/ash/filter/filter.ex:3428: Ash.Filter.do_hydrate_refs/2
    (ash 2.18.2) lib/ash/policy/check/expression.ex:3: Ash.Policy.Check.Expression.try_eval/2
    (ash 2.18.2) lib/ash/policy/check/expression.ex:3: Ash.Policy.Check.Expression.try_strict_check/3
    (ash 2.18.2) lib/ash/policy/policy.ex:165: Ash.Policy.Policy.fetch_or_strict_check_fact/2
    (ash 2.18.2) lib/ash/policy/policy.ex:482: Ash.Policy.Policy.compile_policy_expression/2
    (ash 2.18.2) lib/ash/policy/policy.ex:321: Ash.Policy.Policy.compile_policy_expression/2
    (ash 2.18.2) lib/ash/policy/policy.ex:68: Ash.Policy.Policy.build_requirements_expression/2
    (ash 2.18.2) lib/ash/policy/policy.ex:26: Ash.Policy.Policy.solve/1
    (ash 2.18.2) lib/ash/policy/checker.ex:83: Ash.Policy.Checker.strict_check_scenarios/1
    (ash 2.18.2) lib/ash/policy/authorizer/authorizer.ex:1285: Ash.Policy.Authorizer.strict_check_result/2
    (ash 2.18.2) lib/ash/policy/authorizer/authorizer.ex:482: Ash.Policy.Authorizer.strict_check/2
    (ash 2.18.2) lib/ash/api/api.ex:938: anonymous fn/5 in Ash.Api.run_check/4
    (elixir 1.16.1) lib/enum.ex:4842: Enumerable.List.reduce/3
    (elixir 1.16.1) lib/enum.ex:2582: Enum.reduce_while/3
    (ash 2.18.2) lib/ash/api/api.ex:935: Ash.Api.run_check/4
    (ash 2.18.2) lib/ash/api/api.ex:812: Ash.Api.can/4
    (ash 2.18.2) lib/ash/actions/create/create.ex:138: Ash.Actions.Create.authorize/3
    iex:2: (file)

To Reproduce

  1. Define a code interface for a create or update action
  2. Pass a keyword list of inputs instead of a map
  3. Watch the world burn.

Expected behavior

The user should get an error that indicates that the input is of the incorrect type, rather than a backtrace from a partial attempt to evaluate the params as options.

Runtime

  • Elixir version
  • Erlang version
  • OS
  • Ash version 2.18.2
  • any related extension versions

Additional context
Add any other context about the problem here.

@jimsynz jimsynz added bug Something isn't working needs review labels Apr 8, 2024
@zachdaniel
Copy link
Contributor

Something about this seems very strange. Specifically, the way it fails seems wrong. However, the way we determine the difference between opts lists and input maps is vie type detection, so the error you should get is something like "no such options [:name, ...]"

@zachdaniel
Copy link
Contributor

never mind, you're passing both. 🤔

@zachdaniel
Copy link
Contributor

I don't see how this could possibly be related to passing a keyword list instead of a map in. When I do that I get an error about merging maps. Are you sure the error you posted comes from providing a keyword list?

@zachdaniel
Copy link
Contributor

So, I've got no idea where that particular error is coming from, but I fixed an error that I found when doing the same thing in our tests here: c31fbc9

Seems like there is something else going on for you though, so can you dig some more and confirm that the maps/keyword list is actually the cause?

@jimsynz
Copy link
Contributor Author

jimsynz commented Apr 9, 2024

I'll work up a reproduction for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants