Skip to content

Conversation

@sevenseacat
Copy link
Contributor

When keyset pagination is combined with a relationship sort and loaded aggregates, the query's select contains nested maps like %{calculations: %{__calc__0: expr}}. Ecto doesn't allow nested maps in subquery selects, causing an error.

This fix reuses AshSql.Query.rewrite_nested_selects/1 (already used in distinct.ex and query.ex for the same purpose) to flatten these nested maps before creating the subquery in wrap_in_subquery_for_aggregates.

This PR fixes the failing test added in ash-project/ash_postgres#677

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

…query for aggregates

When keyset pagination is combined with a relationship sort and loaded
aggregates, the query's select contains nested maps like
`%{calculations: %{__calc__0: expr}}`. Ecto doesn't allow nested maps
in subquery selects, causing an error.

This fix reuses `AshSql.Query.rewrite_nested_selects/1` (already used in
`distinct.ex` and `query.ex` for the same purpose) to flatten these
nested maps before creating the subquery in `wrap_in_subquery_for_aggregates`.

Fixes the failing test in ash-project/ash_postgres#677
@sevenseacat
Copy link
Contributor Author

(the dialyzer issue was pre-existing, not caused by changes in this PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants