InvalidFilterValue for read action

I have this relatively simple read action, but it keeps on failing with a %Ash.Error.Query.InvalidFilterValue
read :for_organisation do
argument(:organisation_id, :integer) do
allow_nil?(false)
end

prepare(fn query, _context ->
query
|> Ash.Query.load([:game_meta])
|> Ash.Query.filter(game_meta.organisation_id == ^arg(:organisation_id))
end)
end
read :for_organisation do
argument(:organisation_id, :integer) do
allow_nil?(false)
end

prepare(fn query, _context ->
query
|> Ash.Query.load([:game_meta])
|> Ash.Query.filter(game_meta.organisation_id == ^arg(:organisation_id))
end)
end
This is the relationship in game_meta:
belongs_to(:organisation, McFun.Games.Organisation,
attribute_type: :integer,
attribute_writable?: true
)
belongs_to(:organisation, McFun.Games.Organisation,
attribute_type: :integer,
attribute_writable?: true
)
Any ideas why this is happening?
4 Replies
drumusician
drumusicianOP2y ago
the error that is returned is this:
** (MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidFilterValue{message: nil, value: {:_arg, :organisation_id}, context: #Ecto.Query<from g0 in McFun.Games.Game, as: 0, join: g1 in ^#Ecto.Query<from g0 in McFun.Games.GameMeta, as: 0>, as: 1, on: g0.id == g1.game_id, where: type(as(1).organisation_id, {:parameterized, Ash.Type.Integer.EctoType, []}) ==
type(^{:_arg, :organisation_id}, {:parameterized, Ash.Type.Integer.EctoType, []}), select: struct(g0, [:id, :name, :origin, :inserted_at, :updated_at])>, changeset: nil, query: nil, error_context: [], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}], stacktraces?: true, changeset: nil, query: #Ash.Query<resource: McFun.Games.Game, arguments: %{organisation_id: 1}, filter: #Ash.Filter<game_meta.organisation_id == {:_arg, :organisation_id}>, load: [game_meta: []], errors: [%Ash.Error.Query.InvalidFilterValue{message: nil, value: {:_arg, :organisation_id}, context: #Ecto.Query<from g0 in McFun.Games.Game, as: 0, join: g1 in ^#Ecto.Query<from g0 in McFun.Games.GameMeta, as: 0>, as: 1, on: g0.id == g1.game_id, where: type(as(1).organisation_id, {:parameterized, Ash.Type.Integer.EctoType, []}) ==
type(^{:_arg, :organisation_id}, {:parameterized, Ash.Type.Integer.EctoType, []}), select: struct(g0, [:id, :name, :origin, :inserted_at, :updated_at])>, changeset: nil, query: nil, error_context: [], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}]>, error_context: [nil], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}}
** (MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidFilterValue{message: nil, value: {:_arg, :organisation_id}, context: #Ecto.Query<from g0 in McFun.Games.Game, as: 0, join: g1 in ^#Ecto.Query<from g0 in McFun.Games.GameMeta, as: 0>, as: 1, on: g0.id == g1.game_id, where: type(as(1).organisation_id, {:parameterized, Ash.Type.Integer.EctoType, []}) ==
type(^{:_arg, :organisation_id}, {:parameterized, Ash.Type.Integer.EctoType, []}), select: struct(g0, [:id, :name, :origin, :inserted_at, :updated_at])>, changeset: nil, query: nil, error_context: [], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}], stacktraces?: true, changeset: nil, query: #Ash.Query<resource: McFun.Games.Game, arguments: %{organisation_id: 1}, filter: #Ash.Filter<game_meta.organisation_id == {:_arg, :organisation_id}>, load: [game_meta: []], errors: [%Ash.Error.Query.InvalidFilterValue{message: nil, value: {:_arg, :organisation_id}, context: #Ecto.Query<from g0 in McFun.Games.Game, as: 0, join: g1 in ^#Ecto.Query<from g0 in McFun.Games.GameMeta, as: 0>, as: 1, on: g0.id == g1.game_id, where: type(as(1).organisation_id, {:parameterized, Ash.Type.Integer.EctoType, []}) ==
type(^{:_arg, :organisation_id}, {:parameterized, Ash.Type.Integer.EctoType, []}), select: struct(g0, [:id, :name, :origin, :inserted_at, :updated_at])>, changeset: nil, query: nil, error_context: [], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}]>, error_context: [nil], vars: [], path: [], stacktrace: #Stacktrace<>, class: :invalid}}
barnabasj
barnabasj2y ago
If you do preparations with a function like this you need to get the argument from the query yourself using https://ash-hq.org/docs/module/ash/2.14.12/ash-query#function-get_argument-2 for example
Ash HQ
Module: Ash.Query
View the documentation for Ash.Query on Ash HQ.
drumusician
drumusicianOP2y ago
ah ok, cool. As opposed to doing it like this:
filter(expr(game_meta.organisation_id == ^arg(:organisation_id)))
filter(expr(game_meta.organisation_id == ^arg(:organisation_id)))
barnabasj
barnabasj2y ago
Yes The arg is returning the tuple {:_arg, :organisation_id} you can see in the error message. This pattern is substitute for the actual argument when using the filter option from the read action dsl

Did you find this page helpful?