Skip to content

868 bug/resource based inline aggregates failing from differing targets - #272

Merged
zachdaniel merged 4 commits into
ash-project:mainfrom
arstamm:868-bug/resource-based-inline-aggregates-failing-from-differing-targets
Oct 16, 2026
Merged

zachdaniel merged 4 commits into
ash-project:mainfrom
arstamm:868-bug/resource-based-inline-aggregates-failing-from-differing-targets

Conversation

@arstamm

@arstamm arstamm commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Fix For Inline First Aggregate Mismatch

Contributor Checklist

  • [ ✔️ ] I accept the AI Policy, or AI was not used in the creation of this PR.
  • [ ✔️ ] Bug fixes include regression tests

Description

This is a fix to address the resource-based inline aggregates (issue 868) for the posgres_sql repository.

Problem

Whenever a guest schema and table are passed into the first macro, the resulting query attempts to look up the guest table from the local schema, resulting in a mismatch followed by a crash. So far, I've observed this only happening with the first macro only.

The cause is that when the query is generated, the guest table name is kept, but the schema is forgotten completely. This causes the guest table to be auto assigned to the local schema instead, resulting in a crash.

calculate :latest_report, :string, expr(first(Report, field: :title, query: [ filter: expr(author_name == parent(name)), sort: [inserted_at: :desc] ] ))

Solution

The function resource_to_query in lib/query.ex is now configured with the prefix already assigned to the target schema instead of being set to null. This way, the query generated by this starts out correct and does not need to be corrected later down the line. Any functions that need to override this down the line can still do so.

What this PR Includes

The bug fix in lib/query.ex.

The regression test for this fix can be found here.

@zachdaniel

Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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