fix: duplicate alias in sibling includes silently breaks nested children#1455
Open
ibirrer wants to merge 1 commit intoTanStack:mainfrom
Open
fix: duplicate alias in sibling includes silently breaks nested children#1455ibirrer wants to merge 1 commit intoTanStack:mainfrom
ibirrer wants to merge 1 commit intoTanStack:mainfrom
Conversation
1 task
0141159 to
0c54be0
Compare
When two sibling includes in .select() used the same alias (e.g.,
{ i: issues } and { i: tags }), nested child collections silently
produced empty results. The root cause was that all includes aliases
were flattened into a single namespace — sharing one D2 graph input
and one subscription, so the second sibling's collection data
overwrote the first.
Fix: give each includes subquery its own independent D2 input.
- extractCollectionAliases no longer traverses into IncludesSubquery
nodes, keeping collectionByAlias scoped to the top-level query.
- compileQuery accepts a createInput factory; when processing includes,
each child gets fresh inputs for its source aliases via
collectAllSourceAliases + createInput().
- compileBasePipeline merges the new inputs into inputsCache and
compiledAliasToCollectionId under unique keys (__inc_N_alias),
so each gets its own subscription feeding the correct collection.
0c54be0 to
309e89e
Compare
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.
Summary
When two sibling includes in
.select()use the same alias (e.g.,{ i: issues }and{ i: tags }), nested child collections silently produce empty results. The root cause is that all includes aliases are flattened into a single namespace — sharing one D2 graph input and one subscription, so the second sibling's collection data overwrites the first.Fix
Give each includes subquery its own independent D2 graph input:
extractCollectionAliasesno longer traverses intoIncludesSubquerynodes, keepingcollectionByAliasscoped to the top-level querycompileQueryaccepts acreateInputfactory; when processing includes, each child gets fresh inputs for its source aliasescompileBasePipelinemerges the new inputs intoinputsCacheandcompiledAliasToCollectionIdunder unique keys (__inc_N_alias), so each gets its own subscription feeding the correct collectionTest
Regression test added to
includes.test.ts: sibling includes with duplicate alias"i"— nested comments are populated. Fails without fix, passes with fix.Fixes #1454