You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ecto.QueryError: when loading aggregates in the query with Ash.Query.load #190
I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
Versions
Elixir: 1.18.4
Erlang/OTP: 28.1
Ash: 3.9.0
AshPostgres: 2.6.25
AshSql: 0.3.12
Ecto: 3.13.5
EctoSql: 3.13.2
Postgrex: 0.21.1
Operating system
macOS
Current Behavior
When loading aggregates in a query, Ash generates an Ecto query with select: merge(struct, map) which fails with:
** (Ecto.QueryError) cannot select_merge source "files" into
merge(&0, %{count_contacts_enabled: coalesce(as(1).count_contacts_enabled(), ^0)}),
those select expressions are incompatible. You can only select_merge:
* a source (such as post) with another source (of the same type)
* a source (such as post) with a map
* a struct with a map
* a map with a map
Incompatible merge found
in query:
from f0 in File,
as: 0,
left_lateral_join: c1 in ^#Ecto.Query<...>,
as: 1,
on: true,
where: ...,
select: merge(
struct(f0, [...]),
%{count_contacts_enabled: coalesce(as(1).count_contacts_enabled, ^0)}
)
This was working on previous versions and when updating ash from 3.5.43 to a recent version it started raising the error, so was expected to work as before.
Hey @zachdaniel i have updated and tested again in my app and the reproduction repo, it now does not have the select_merge issue, but has another issue. The count is not loaded at all, seems like if i try to load 2 things for the same relationship it only loads the first one?
e.g. if i remove :count_contacts it loads :count_contacts_enabled fine:
Activity
zachdaniel commentedon Nov 15, 2025
related: elixir-ecto/ecto#4680
zachdaniel commentedon Nov 16, 2025
I believe this is fixed in
maindiogomrts commentedon Nov 27, 2025
Hey @zachdaniel i have updated and tested again in my app and the reproduction repo, it now does not have the select_merge issue, but has another issue. The count is not loaded at all, seems like if i try to load 2 things for the same relationship it only loads the first one?
e.g. if i remove
:count_contactsit loads:count_contacts_enabledfine:but with both, only loads the count_contacts:
should i make another github issue?
zachdaniel commentedon Nov 27, 2025
Have you also updated
ash_postgresandash? Just to make sure?zachdaniel commentedon Nov 27, 2025
And you're definitely on ash_sql 0.3.14?
diogomrts commentedon Nov 27, 2025
Yes just did a full update for all deps, here is the commit just to e sure nothing is missing 😅
diogomrts/test_repo@dc13dbd#diff-f9ea769f3d62f6ebfee2c6ef453a579ab051c1b45514ecfc2ffba9d9e98a5025L5-R5
zachdaniel commentedon Nov 28, 2025
@diogomrts fixed in the latest
ash_sql