ash-project / ash_postgres

The PostgreSQL data layer for Ash Framework
https://hexdocs.pm/ash_postgres
MIT License
134 stars 73 forks source link

%KeyError{key: :__ash_bindings__} on filter expression #374

Closed TimisRobert closed 2 weeks ago

TimisRobert commented 2 weeks ago

Given this oban trigger:

trigger :archive do
  action :destroy
  on_error :error
  where expr(
    updated_at < ago(30, :minute) 
    and not is_nil(items) # If I remove this it works
    and not exists(items.item.sub_items, updated_at > ago(30, :minute)) # if I remove this it works
    # and not exists(items.item.sub_items, true)) if I use this it works
  )
  scheduler_cron "*/30 * * * *"
end

When triggered it will error with:

** (Ash.Error.Unknown) Unknown Error\n\n* %KeyError{key: :__ash_bindings__, term: <full query>}
(ash_sql 0.2.30) lib/query.ex:139: AshSql.Query.return_query/2
(ash 3.4.1) lib/ash/query/query.ex:2988: Ash.Query.data_layer_query/2
(ash 3.4.1) lib/ash/actions/read/read.ex:467: anonymous fn/7 in Ash.Actions.Read.do_read/4
(ash 3.4.1) lib/ash/actions/read/read.ex:826: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.4.1) lib/ash/actions/read/read.ex:249: Ash.Actions.Read.do_run/3
(ash 3.4.1) lib/ash/actions/read/read.ex:66: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.4.1) lib/ash/actions/read/read.ex:65: Ash.Actions.Read.run/3
(ash 3.4.1) lib/ash.ex:2009: Ash.do_read_one/3
(ash 3.4.1) lib/ash.ex:1958: Ash.read_one/2
(myapp 0.1.0) deps/ash_oban/lib/transformers/define_schedulers.ex:390: anonymous fn/4 in MyApp.AshOban.Worker.Archive.prepare/4
(ash 3.4.1) lib/ash/changeset/changeset.ex:3491: anonymous fn/2 in Ash.Changeset.run_before_actions/1
(elixir 1.17.2) lib/enum.ex:4858: Enumerable.List.reduce/3
(elixir 1.17.2) lib/enum.ex:2585: Enum.reduce_while/3
(ash 3.4.1) lib/ash/changeset/changeset.ex:3468: Ash.Changeset.run_before_actions/1
(ash 3.4.1) lib/ash/changeset/changeset.ex:3604: Ash.Changeset.run_around_actions/2
(ash 3.4.1) lib/ash/changeset/changeset.ex:3162: anonymous fn/3 in Ash.Changeset.with_hooks/3
(ecto_sql 3.12.0) lib/ecto/adapters/sql.ex:1382: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
(db_connection 2.7.0) lib/db_connection.ex:1756: DBConnection.run_transaction/4
(ash 3.4.1) lib/ash/changeset/changeset.ex:3160: anonymous fn/3 in Ash.Changeset.with_hooks/3

Runtime

zachdaniel commented 2 weeks ago

This should be fixed in main.