Skip to content
Source
Sign inSign up
TanStack/db

Duplicate alias in sibling includes silently breaks nested children #1454

Send to my agent
Closedibirrer(GitHub profile, opens in a new tab) opened this issue 0 comments
  • I've validated the bug against the latest version of DB packages

Describe the bug When two sibling includes in .select() use the same alias letter, nested child collections silently produce empty results. No error or warning is produced — data is silently lost.

For example, if an issues include uses { i: issues } and a sibling tags include uses { i: tags }, any nested grandchild inside issues (e.g., comments) returns empty. Changing the tags alias to { t: tags } fixes it.

Reproducible with this test in PR #1455.

Steps to Reproduce

const collection = createLiveQueryCollection((q) =>
  q.from({ p: projects }).select(({ p }) => ({
    id: p.id,
    issues: q
      .from({ i: issues })          // alias "i"
      .where(({ i }) => eq(i.projectId, p.id))
      .select(({ i }) => ({
        id: i.id,
        comments: q                  // nested grandchild
          .from({ c: comments })
          .where(({ c }) => eq(c.issueId, i.id))
          .select(({ c }) => ({ id: c.id, body: c.body })),
      })),
    tags: q
      .from({ i: tags })            // same alias "i" — breaks comments above
      .where(({ i }) => eq(i.projectId, p.id))
      .select(({ i }) => ({ id: i.id, label: i.label })),
  })),
)

await collection.preload()

const alpha = collection.get(1)
const issue10 = alpha.issues.get(10)
issue10.comments // empty — should contain comments for issue 10

Observed Behavior

  • tags is populated correctly
  • issues contains rows, but they come from the wrong collection (tags data routed to the issues pipeline)
  • Nested comments inside issues is always empty
  • No error or warning is thrown

Expected Behavior

Aliases in sibling includes should be independent scopes. Using the same alias letter in different sibling subqueries should just work — each gets its own data pipeline.

  1. tannerlinsley closed this

Sign in to join this conversation.