no FunctionClause matching when loading calculation

Hi, somewhere between this commit de943509f73ff0c6ef3749feb3cc6ab6e4d99d2d and now, I started getting an error in one of my graphql queries.
[error] Task #PID<0.6039.0> started from #PID<0.6032.0> terminating
** (Ash.Error.Unknown) Unknown Error

Context: resolving data on calculate hotel_itinerary_items.sort_order
* Context: resolving data on calculate hotel_itinerary_items.sort_order

** (FunctionClauseError) no function clause matching in Ash.Actions.Read.run_query/6
(ash 2.6.31) lib/ash/actions/read.ex:2208: Ash.Actions.Read.run_query(#Ash.Query<resource: Demo.Offer.Resources.ItineraryItem.HotelItineraryItem, filter: #Ash.Filter<id in ["0a23ede2-ff04-4636-949f-321f9c9a4314", "5e65f643-7463-4456-8d19-e46c370f7950"]>>, #Ecto.Query<from h0 in JdlEngine.Offer.Resources.ItineraryItem.HotelItineraryItem, as: 0, where: type(as(0).id, {:parameterized, Ash.Type.UUID.EctoType, []}) in [
type(^"0a23ede2-ff04-4636-949f-321f9c9a4314", {:parameterized, Ash.Type.UUID.EctoType, []}),
type(^"5e65f643-7463-4456-8d19-e46c370f7950", {:parameterized, Ash.Type.UUID.EctoType, []})
], select: merge(merge(h0, %{}), %{
sort_order:
type(
fragment(
"(select sort_order from offer_itinerary_item oii where id = ? and item_type = ?)",
type(as(0).id, {:parameterized, Ash.Type.UUID.EctoType, []}),
^"h"
),
{:parameterized, Ash.Type.Integer.EctoType, []}
)
})>, %{actor: %{id: "App User", roles: [:admin]}, api: Demo.Support, authorize?: true, tenant: nil}, false, [], [])
(ash 2.6.31) lib/ash/actions/read.ex:2697: Ash.Actions.Read.run_calculation_query/6
(ash 2.6.31) lib/ash/actions/read.ex:1529: anonymous fn/14 in Ash.Actions.Read.calculation_dependency_requests/9
(ash 2.6.31) lib/ash/engine/request.ex:1048: Ash.Engine.Request.do_try_resolve_local/4
(ash 2.6.31) lib/ash/engine/request.ex:282: Ash.Engine.Request.do_next/1
(ash 2.6.31) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
(ash 2.6.31) lib/ash/engine/engine.ex:719: Ash.Engine.advance_request/2
(ash 2.6.31) lib/ash/engine/engine.ex:625: Ash.Engine.fully_advance_request/2
(ash 2.6.31) lib/ash/engine/engine.ex:566: Ash.Engine.do_run_iteration/2
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.6.31) lib/ash/engine/engine.ex:307: Ash.Engine.run_to_completion/1
(ash 2.6.31) lib/ash/engine/engine.ex:252: Ash.Engine.do_run/2
(ash 2.6.31) lib/ash/engine/engine.ex:148: Ash.Engine.run/2
(ash 2.6.31) lib/ash/actions/read.ex:173: Ash.Actions.Read.do_run/3
(ash 2.6.31) lib/ash/actions/read.ex:96: Ash.Actions.Read.run/3
(ash 2.6.31) lib/ash/api/api.ex:1349: Ash.Api.load!/4
(ash_graphql 0.23.3) lib/graphql/dataloader.ex:318: Dataloader.Source.AshGraphql.Dataloader.run_batch/2
(ash_graphql 0.23.3) lib/graphql/dataloader.ex:182: anonymous fn/2 in Dataloader.Source.AshGraphql.Dataloader.run_batches/1
(elixir 1.14.3) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(elixir 1.14.3) lib/task/supervised.ex:34: Task.Supervised.reply/4

[error] Task #PID<0.6039.0> started from #PID<0.6032.0> terminating
** (Ash.Error.Unknown) Unknown Error

Context: resolving data on calculate hotel_itinerary_items.sort_order
* Context: resolving data on calculate hotel_itinerary_items.sort_order

** (FunctionClauseError) no function clause matching in Ash.Actions.Read.run_query/6
(ash 2.6.31) lib/ash/actions/read.ex:2208: Ash.Actions.Read.run_query(#Ash.Query<resource: Demo.Offer.Resources.ItineraryItem.HotelItineraryItem, filter: #Ash.Filter<id in ["0a23ede2-ff04-4636-949f-321f9c9a4314", "5e65f643-7463-4456-8d19-e46c370f7950"]>>, #Ecto.Query<from h0 in JdlEngine.Offer.Resources.ItineraryItem.HotelItineraryItem, as: 0, where: type(as(0).id, {:parameterized, Ash.Type.UUID.EctoType, []}) in [
type(^"0a23ede2-ff04-4636-949f-321f9c9a4314", {:parameterized, Ash.Type.UUID.EctoType, []}),
type(^"5e65f643-7463-4456-8d19-e46c370f7950", {:parameterized, Ash.Type.UUID.EctoType, []})
], select: merge(merge(h0, %{}), %{
sort_order:
type(
fragment(
"(select sort_order from offer_itinerary_item oii where id = ? and item_type = ?)",
type(as(0).id, {:parameterized, Ash.Type.UUID.EctoType, []}),
^"h"
),
{:parameterized, Ash.Type.Integer.EctoType, []}
)
})>, %{actor: %{id: "App User", roles: [:admin]}, api: Demo.Support, authorize?: true, tenant: nil}, false, [], [])
(ash 2.6.31) lib/ash/actions/read.ex:2697: Ash.Actions.Read.run_calculation_query/6
(ash 2.6.31) lib/ash/actions/read.ex:1529: anonymous fn/14 in Ash.Actions.Read.calculation_dependency_requests/9
(ash 2.6.31) lib/ash/engine/request.ex:1048: Ash.Engine.Request.do_try_resolve_local/4
(ash 2.6.31) lib/ash/engine/request.ex:282: Ash.Engine.Request.do_next/1
(ash 2.6.31) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
(ash 2.6.31) lib/ash/engine/engine.ex:719: Ash.Engine.advance_request/2
(ash 2.6.31) lib/ash/engine/engine.ex:625: Ash.Engine.fully_advance_request/2
(ash 2.6.31) lib/ash/engine/engine.ex:566: Ash.Engine.do_run_iteration/2
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.6.31) lib/ash/engine/engine.ex:307: Ash.Engine.run_to_completion/1
(ash 2.6.31) lib/ash/engine/engine.ex:252: Ash.Engine.do_run/2
(ash 2.6.31) lib/ash/engine/engine.ex:148: Ash.Engine.run/2
(ash 2.6.31) lib/ash/actions/read.ex:173: Ash.Actions.Read.do_run/3
(ash 2.6.31) lib/ash/actions/read.ex:96: Ash.Actions.Read.run/3
(ash 2.6.31) lib/ash/api/api.ex:1349: Ash.Api.load!/4
(ash_graphql 0.23.3) lib/graphql/dataloader.ex:318: Dataloader.Source.AshGraphql.Dataloader.run_batch/2
(ash_graphql 0.23.3) lib/graphql/dataloader.ex:182: anonymous fn/2 in Dataloader.Source.AshGraphql.Dataloader.run_batches/1
(elixir 1.14.3) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(elixir 1.14.3) lib/task/supervised.ex:34: Task.Supervised.reply/4

I tried to look at it, but I wasn't able to figure it out yet. It happens when the :unkown branch is executed here: https://github.com/ash-project/ash/blob/5005d57b1db3522a09accc6f10418ac230fe2c40/lib/ash/actions/read.ex#L1526 The context inside the query is empty and no action is set, therefore no run_query function matches. The calulation it's trying to load is a simple expr calulcation with a fragment inside on a resource using AshPostgres Datalayer, no args are anything.
GitHub
ash/read.ex at 5005d57b1db3522a09accc6f10418ac230fe2c40 · ash-proje...
A declarative and extensible framework for building Elixir applications. - ash/read.ex at 5005d57b1db3522a09accc6f10418ac230fe2c40 · ash-project/ash
6 Replies
ZachDaniel
ZachDaniel•3y ago
Mind opening an issue in Ash? Just pushed something up to main that might resolve this issue.
barnabasj
barnabasjOP•3y ago
I'm getting a different error now, I'll move this to a github issue.
barnabasj
barnabasjOP•3y ago
GitHub
no FunctionClause matching when loading calculation · Issue #568 · ...
Describe the bug Hi, somewhere between this commit de94350 and now, I started getting an error in one of my graphql queries. [error] Task #PID<0.6039.0> started from #PID<0.6032.0> term...
ZachDaniel
ZachDaniel•3y ago
Hey @barnabasj so I have a test that gets to that branch of code, but it works for me, both loading it directly on the record, and loading the record from a relationship and then loading the calculation (which is what it looks like you're doing). I'll probably need to see the graphql query thats causing the issue Haven't reproduced the issue, but I did find a potential cause of the issue, so you can try out ash main
barnabasj
barnabasjOP•3y ago
Thanks, I'll try it shortly. That fixed it, 🙇 thank you very much
ZachDaniel
ZachDaniel•3y ago
🥳 I'm glad that worked 😅

Did you find this page helpful?