Skip to content

fix: preserve shared context in lateral join source queries#238

Merged
zachdaniel merged 1 commit into
ash-project:mainfrom
nallwhy:fix/preserve-shared-context-in-lateral-joins
Jul 13, 2026
Merged

fix: preserve shared context in lateral join source queries#238
zachdaniel merged 1 commit into
ash-project:mainfrom
nallwhy:fix/preserve-shared-context-in-lateral-joins

Conversation

@nallwhy

@nallwhy nallwhy commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

Summary

Preserve the source query's :shared context when reconstructing a lateral join source query in AshSql.Query.set_context/4.

Previously, the query was rebuilt from its resource with only the :data_layer context restored. This dropped :shared before parent relationship paths were joined.

Impact

The missing context affected relationship filters containing correlated parent() expressions that traverse relationships on the parent resource.

When a resource on that path had a global preparation depending on context.source_context[:shared], the preparation ran without the caller-provided shared context.

Copilot AI review requested due to automatic review settings July 13, 2026 07:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes lateral-join query reconstruction so that caller-provided :shared context is preserved when rebuilding a lateral join source query, ensuring global preparations that depend on context.source_context[:shared] still receive that context during parent-path relationship traversal.

Changes:

  • Refactors lateral join source query reconstruction into a dedicated helper (rebuild_lateral_join_source_query/1) that carries forward :shared while still normalizing :data_layer context.
  • Adds a regression test that validates :shared context survives the rebuild and is visible to a preparation triggered via a parent() relationship path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/query.ex Uses a new helper to rebuild lateral join source queries while preserving :shared context and keeping existing :data_layer normalization behavior.
test/query_test.exs Adds a regression test covering :shared context preservation through a parent() relationship path that triggers a preparation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zachdaniel
zachdaniel merged commit 467de7c into ash-project:main Jul 13, 2026
24 of 25 checks passed
@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.

3 participants