I have a calculation like this:
defmodule MyApp.LocalisedName do
use Ash.Resource.Calculation
@impl true
def load(_query, _opts, _context) do
[trans: [:language, :name]]
end
@impl true
def expression(_opts, _ctx) do
expr(first(trans, [field: :name, filter: expr(language == ^context(:locale))]))
end
end
where trans is a relationship for translations. Those have an “id”, a “name” and a “language”. My scope looks like this:
scope = %MyApp.Scope{current_user: user, current_tenant: :gr, locale: "de"}
this results in an error like this:
iex(17)> MyApp.Accounts.search_user("are", scope: scope)
** (Ash.Error.Unknown)
Bread Crumbs:
> Exception raised in: MyApp.Accounts.User.search
Unknown Error
* ** (RuntimeError) Unsupported expression in Elixir.AshPostgres.SqlImplementation query: {:_context, :locale}
(ash_sql 0.3.15) lib/expr.ex:2721: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/expr.ex:2024: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/expr.ex:1380: anonymous fn/13 in AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/filter.ex:42: anonymous fn/2 in AshSql.Filter.add_filter_expression/2
(elixir 1.19.3) lib/enum.ex:2520: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_sql 0.3.15) lib/filter.ex:26: AshSql.Filter.filter/4
(ash_sql 0.3.15) lib/aggregate.ex:1371: anonymous fn/6 in AshSql.Aggregate.maybe_filter_subquery/6
(elixir 1.19.3) lib/enum.ex:5023: Enumerable.List.reduce/3
(elixir 1.19.3) lib/enum.ex:2574: Enum.reduce_while/3
(ash_sql 0.3.15) lib/aggregate.ex:664: anonymous fn/10 in AshSql.Aggregate.get_subquery/12
(ash_sql 0.3.15) lib/join.ex:368: AshSql.Join.related_subquery/3
(ash_sql 0.3.15) lib/aggregate.ex:318: anonymous fn/7 in AshSql.Aggregate.add_aggregates/6
(elixir 1.19.3) lib/enum.ex:5023: Enumerable.List.reduce/3
(elixir 1.19.3) lib/enum.ex:2574: Enum.reduce_while/3
(ash_sql 0.3.15) lib/aggregate.ex:157: AshSql.Aggregate.add_aggregates/6
(ash_postgres 2.6.26) lib/data_layer.ex:3513: AshPostgres.DataLayer.filter/4
(ash 3.10.0) lib/ash/query/query.ex:4752: Ash.Query.maybe_filter/3
(ash 3.10.0) lib/ash/query/query.ex:4504: Ash.Query.data_layer_query/2
(ash_sql 0.3.15) lib/join.ex:475: AshSql.Join.related_query/3
(ash_sql 0.3.15) lib/join.ex:348: AshSql.Join.related_subquery/3
(ash_sql 0.3.15) lib/expr.ex:2721: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/expr.ex:2024: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/expr.ex:1380: anonymous fn/13 in AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.3.15) lib/filter.ex:42: anonymous fn/2 in AshSql.Filter.add_filter_expression/2
(elixir 1.19.3) lib/enum.ex:2520: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_sql 0.3.15) lib/filter.ex:26: AshSql.Filter.filter/4
(ash_sql 0.3.15) lib/aggregate.ex:1371: anonymous fn/6 in AshSql.Aggregate.maybe_filter_subquery/6
(elixir 1.19.3) lib/enum.ex:5023: Enumerable.List.reduce/3
(elixir 1.19.3) lib/enum.ex:2574: Enum.reduce_while/3
(ash_sql 0.3.15) lib/aggregate.ex:664: anonymous fn/10 in AshSql.Aggregate.get_subquery/12
(ash_sql 0.3.15) lib/join.ex:368: AshSql.Join.related_subquery/3
(ash_sql 0.3.15) lib/aggregate.ex:318: anonymous fn/7 in AshSql.Aggregate.add_aggregates/6
(elixir 1.19.3) lib/enum.ex:5023: Enumerable.List.reduce/3
(elixir 1.19.3) lib/enum.ex:2574: Enum.reduce_while/3
(ash_sql 0.3.15) lib/aggregate.ex:157: AshSql.Aggregate.add_aggregates/6
(ash_postgres 2.6.26) lib/data_layer.ex:3513: AshPostgres.DataLayer.filter/4
(ash 3.10.0) lib/ash/query/query.ex:4752: Ash.Query.maybe_filter/3
(ash 3.10.0) lib/ash/query/query.ex:4504: Ash.Query.data_layer_query/2
(ash_sql 0.3.15) lib/join.ex:475: AshSql.Join.related_query/3
iex:17: (file)
If I do this:
expr(first(trans, [field: :name, filter: expr(language == "fr"))]))
then it works just fine.
I’m on the newest dependencies for:
- ash
- ash_postgres
- ash_sql























