Skip to content

exists aggregation ignores filter option #173

Closed
@smt116

Description

@smt116

Describe the bug

exists aggregation ignores filter option.

To Reproduce

Define a resource with has_many relation. Then, in the parent, define the following aggregation:

aggregates do
  exists :has_obsolete_children, :children do
    filter expr(parent.state == :processing and parent.updated_at > updated_at)
  end
end

Now, loading that aggregation will include all children no matter of the filter expression. The produced SQL query won't include the state or timestamps checks. Note that these will be applied after changing exists to, e.g., count aggregation.

Expected behavior
exists should apply filter option to the SQL query and produce correct result.

** Runtime

  • Elixir version 1.15.4-otp-26
  • Erlang version 26.0.2
  • OS macOS
  • Ash version
  "ash": {:git, "https://github.com/ash-project/ash.git", "ecdc4c1c6476908b764352d08153d269a0f58e4d", []},
  "ash_authentication": {:git, "https://github.com/team-alembic/ash_authentication.git", "a0dd7796e1f17b4cb9cd33d0ba31b63065fe4c56", []},
  "ash_authentication_phoenix": {:git, "https://github.com/team-alembic/ash_authentication_phoenix.git", "e3e2f811e798c094d067dc4e9c2b86045bc44220", []},
  "ash_graphql": {:git, "https://github.com/ash-project/ash_graphql.git", "34fd3139019bcd790470ae4bd5b49a7231f1bf15", []},
  "ash_json_api": {:hex, :ash_json_api, "0.31.3", "a3b9a18512c04e16eff7901c4eac15822d7ad9488cc309211cbb28e15a038fd7", [:mix], [{:ash, "~> 2.3", [hex: :ash, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4.0", [hex: :json_xema, repo: "hexpm", optional: false]}, {:open_api_spex, "~> 3.16", [hex: :open_api_spex, repo: "hexpm", optional: true]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "8e7ba50077e969bc32a129fb3c23a515451c9a1fccae355da552bce4c9023143"},
  "ash_oban": {:git, "https://github.com/ash-project/ash_oban.git", "4131a316d91c832320936012b6fc873325668aaa", []},
  "ash_phoenix": {:hex, :ash_phoenix, "1.2.19", "c13f7e6acb2d06f0e3742a35f12b08f6fabf5dd7338b3332b645c86a74d44164", [:mix], [{:ash, ">= 2.5.10 and < 3.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.5.6 or ~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.15", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "a36bc916ccc2f85b86f3ac86c264c30ad0e6ab61c8b1c12f68573742241dbdf5"},
  "ash_postgres": {:git, "https://github.com/ash-project/ash_postgres.git", "270d8685e7031d261e43703b8ace4621ef98dba6", []},
  "ash_state_machine": {:git, "https://github.com/ash-project/ash_state_machine.git", "fa109180e4c15ddfdc42e625b7a08417c376c54c", []},

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions