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

Using ref in a filter gives an error in ash 3 #283

Closed
ahey opened this issue May 15, 2024 · 3 comments
Closed

Using ref in a filter gives an error in ash 3 #283

ahey opened this issue May 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ahey
Copy link
Contributor

ahey commented May 15, 2024

Describe the bug
Filtering on a ref was working up until Ash 3.0. Now, it gives an error.

To Reproduce
A PR with a failing test has been added to demonstrate the error. Running the test give the following error:

  1. test filter with ref (AshPostgres.FilterTest)
    test/filter_test.exs:1076
    ** (FunctionClauseError) no function clause matching in Ash.Filter.check_filterable/2

    The following arguments were given to Ash.Filter.check_filterable/2:

      # 1
      AshPostgres.Test.Organization
    
      # 2
      :id
    

    Attempted function clauses (showing 2 out of 2):

      defp check_filterable(_resource, [])
      defp check_filterable(resource, [relationship | rest])
    

    code: |> Ash.Query.filter(^ref(:id, [:posts, :comments]) == ^comment.id)
    stacktrace:
    (ash 3.0.1) lib/ash/filter/filter.ex:2944: Ash.Filter.check_filterable/2
    (ash 3.0.1) lib/ash/filter/filter.ex:2933: anonymous fn/2 in Ash.Filter.validate_filterable_relationship_paths/2
    (elixir 1.16.2) lib/enum.ex:4316: Enum.find_value_list/3
    (ash 3.0.1) lib/ash/filter/filter.ex:2923: Ash.Filter.validate_refs/3
    (ash 3.0.1) lib/ash/filter/filter.ex:3015: Ash.Filter.resolve_call/2
    (ash 3.0.1) lib/ash/filter/filter.ex:2489: Ash.Filter.add_expression_part/3
    (ash 3.0.1) lib/ash/filter/filter.ex:2427: anonymous fn/3 in Ash.Filter.parse_expression/2
    (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3
    (elixir 1.16.2) lib/enum.ex:2582: Enum.reduce_while/3
    (ash 3.0.1) lib/ash/filter/filter.ex:334: Ash.Filter.parse/3
    (ash 3.0.1) lib/ash/query/query.ex:2574: Ash.Query.do_filter/3
    test/filter_test.exs:1095: (test)

@ahey ahey added bug Something isn't working needs review labels May 15, 2024
@zachdaniel
Copy link
Contributor

So, not sure if this changed in 2.0 -> 3.0, if so, sorry about that :)

But its ^ref([:path, :to], :field)

@zachdaniel
Copy link
Contributor

I'm adding some pattern matching to ref/2 and ref/1 to help make it clearer.

@ahey
Copy link
Contributor Author

ahey commented May 15, 2024

Thanks Zach!

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