test: reproduce parent() scoping bug in nested exists with calculation#717
Merged
zachdaniel merged 1 commit intomainfrom Mar 22, 2026
Merged
test: reproduce parent() scoping bug in nested exists with calculation#717zachdaniel merged 1 commit intomainfrom
zachdaniel merged 1 commit intomainfrom
Conversation
When a calculation on resource B uses `parent()` inside an unrelated `exists()`, and resource A references that calculation via `exists(relationship_to_b, b_calculation)`, the `parent()` references incorrectly resolve to resource A instead of resource B. Example: Post has `exists(Author, first_name == parent(title))` where parent(title) should refer to Post.title. When Author uses `exists(posts, that_post_calculation)`, the generated SQL produces `authors.title` instead of `posts.title`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
When a calculation on resource B uses
parent()inside an unrelatedexists(), and resource A references that calculation viaexists(relationship_to_b, b_calculation), theparent()references incorrectly resolve to resource A instead of resource B.Reproduction
Post has a calculation using an unrelated exists with
parent():When loaded directly on a Post,
parent(title)correctly refers toPost.title.Author has a calculation that uses the Post calculation via a relationship exists:
When loaded on Author, the generated SQL resolves
parent(title)toauthors.titleinstead ofposts.title:What's Included
Impact
This prevents using
exists(relationship, calculation)when the calculation itself containsparent()references inside an unrelatedexists(). The workaround is to inline the calculation logic with explicit parent scoping or use a module calculation instead.