Skip to content

Keep the id in an include's temp table when the queried document has duplicated fields (#5650) - #5651

Merged
jeremydmiller merged 2 commits into
JasperFx:masterfrom
Blackclaws:fix/reverse-include-on-id-query-session
Oct 13, 2026
Merged

jeremydmiller merged 2 commits into
JasperFx:masterfrom
Blackclaws:fix/reverse-include-on-id-query-session

Conversation

@Blackclaws

Copy link
Copy Markdown
Contributor

Fixes #5650.

An Include() joined on the queried document's own id failed with 42703: column d.id does not exist in a query session whenever the queried document had a duplicated field. The include's temp table was built from the DuplicatedFieldSelectClause, which a query session builds without the id column.

Change

TemporaryTableStatement already swaps a query session's select clause for one that carries the id. It now does the equivalent for a DuplicatedFieldSelectClause, calling EnsureColumn("d.id"). That's the same mechanism LINQ joins already use for their key column (EnsureJoinKeyInCte). In the other session kinds the id is already selected, so the call does nothing.

Commits

  1. Failing test. LinqTests/Includes/include_on_the_queried_document_id.cs is a theory over query, lightweight, identity-map and dirty-tracked sessions, each with and without a duplicated field on the queried document. Before the fix, only query + duplicated failed.
  2. The fix. Seven lines in TemporaryTableStatement.

Testing

Run locally on net10.0 against PostgreSQL:

  • the new test: 8 of 8 pass;
  • LinqTests: 1617 passed, 0 failed;
  • CompiledQueryTests: 9 passed.

No public API changes.

Blackclaws and others added 2 commits October 13, 2026 10:29
…om a query session

When the queried document has a duplicated field, the include's temp table is built
from the duplicated-field select clause, which a query session builds without the id
column. The include's join then reads d.id from that temp table and Postgres answers
42703 "column d.id does not exist". Every other session kind, and a query session on a
document without duplicated fields, carries the id and passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…duplicated fields

TemporaryTableStatement already swaps a query session's select clause for one that carries
the id, "just in case" something downstream needs it. A document with duplicated fields
reaches it through DuplicatedFieldSelectClause instead, which that check did not recognise,
so the id was dropped and an include joined on the queried document's id failed with
42703. Ensure the id column on that clause too, the same way LINQ joins already ensure
their key column (EnsureJoinKeyInCte).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jeremydmiller
jeremydmiller merged commit 0acb6ea into JasperFx:master Oct 13, 2026
32 checks passed
@jeremydmiller

Copy link
Copy Markdown
Member

Merged, thanks @Blackclaws — nice minimal fix, and the theory over all four session kinds made the A/B easy to verify (1/8 red on master, 8/8 green with the fix).

While reviewing I probed the adjacent shapes. Select() and Take() are fine, but a query session that also calls .Stats(out var stats) still fails with the same 42703 — and that one does not depend on a duplicated field, so it's a separate pre-existing hole rather than anything this PR missed. The StatsSelectClause wrapper means neither branch of the if fires. Filed as #5653 with the suggested fix.

If you want to pick that one up too, include_on_the_queried_document_id is the natural place for the coverage.

This was referenced Oct 14, 2026
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.

Include joined on the queried document's id fails with 42703 in a query session when the document has a duplicated field

2 participants