Skip to content

Conversation

@barnabasJ
Copy link
Contributor

This should fix ash-project/ash_postgres#644
I cloned it locally and the test passes now on my machine

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

Add extract_parent_referenced_fields/1 function to analyze filter
expressions and identify fields referenced through parent() calls.
This will be used to ensure these fields are available in subqueries
when aggregates use parent filters.
@barnabasJ barnabasJ self-assigned this Nov 1, 2025
@barnabasJ barnabasJ added the bug Something isn't working label Nov 1, 2025
|> Enum.uniq()
end

defp extract_refs_from_expr(attribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't think that this is quite enough. The aggregate could reference calculations which themselves reference fields etc.

I think the fix is to select everything in the subquery and then only select the appropriate fields when selecting from the subquery. Which TBH is a bit harder and I'm not entirely sure what the best path is.

You could possibly extract the field names selected from the underlying built query's select expr, then select merge all attributes, then select from the subquery the field names you originally got.

@zachdaniel zachdaniel closed this Nov 9, 2025
@zachdaniel
Copy link
Contributor

Fixed and released the modified strategy I discussed

🚀 Thank you for your contribution! 🚀

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants