Skip to content

fix: a declaration on a type of TPC whose derived types have tables is refused - #131

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/tpc-type-with-derived-types
Nov 14, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/tpc-type-with-derived-types

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #101

Problem

Reservation is the concrete root of a TPC hierarchy, with Stay and Hold in tables of their own. DeclarePostgres on Reservation gave:

CREATE EXTENSION IF NOT EXISTS btree_gist;
ALTER TABLE reservations ADD CONSTRAINT ex_res EXCLUDE USING gist ("RoomId" WITH =, "Period" WITH &&);

Nothing for stays and holds, and no error: overlapping rows in either were accepted. EF Core gives an index declared on such a type to every table of the hierarchy, and 5.x gave each a copy of an exclusion constraint, so a consumer expects the same. An abstract root was refused already, for having no table; the 5.x reader refuses a root with derived types. A declaration written here on a type that has a table was the case that passed.

It is #82 the other way round: there a declaration on a derived type reached a table it shares, here one on a base type misses the tables below it. Both follow from a declaration being resolved against one table.

Change

Tests

Locally, after a rebase onto main with #103, #110 and #124 in it: 622 kernel tests, 198 of the PostgreSQL package with the live ones on PostgreSQL 16 and 18, 125 probes.

  • SchemaOperationPlannerTests, on Npgsql, SQL Server and SQLite with the sample contributor: refused on an abstract root (naming Car, Truck, Roadster), on a type with a table and a derived type (naming Roadster), and on a root above an abstract type (naming Caravan alone), also by HasDifferences; declared on two types without derived types, each index in its own table on the inherited column; a snapshot that holds a declaration on such a type is read where a diff starts and where one ends.
  • PgExclusionMigrationTests: the model of the issue is refused; the constraint on Stay is one statement for stays.
  • PgExclusionLiveTests: that constraint applied on PostgreSQL 16 and 18, with the catalog EnsureCreated() builds.

Guards shown to fail, four defects seeded one at a time in a scratch copy:

Seed Tests that fail
No type has tables below it the refusal on all three providers, and the PostgreSQL package's
Refused in every model, not only the context's own the snapshot's
Only the direct derived types the refusal on all three providers (the root's message loses Roadster)
Derived types without a table counted too the refusal on all three providers (the message gains Trailer)

Decisions in this PR that are not confirmed

Not in this PR

The 5.x reader's own refusal of a TPC root stays as it is: it goes with #118, when a 5.x snapshot of such a hierarchy can be matched.

🤖 Generated with Claude Code

…s refused, not left on one table

A declaration is resolved against one table. On the root of a TPC hierarchy,
or on any type of one whose derived types have tables of their own, it
reached that type's table alone: the derived types' tables got nothing, and
nothing said so. EF Core gives an index declared on such a type to every
table, and 5.x gave each a copy of an exclusion constraint.

Until a declaration is carried to every table (#118), one on such a type is
refused in the context's own model, naming the derived types that have
tables. A root without a table is refused the same way. A type without
derived types has one table, its own, and is declared on as before, on the
columns it inherits too. A snapshot that holds such a declaration is read.

Closes #101

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 14, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing; the fix ships as a minor, never a patch severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/constraints Exclusion constraints, row guards and other constraint-like objects labels Nov 14, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 010ff31 into main Nov 14, 2026
7 of 8 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/tpc-type-with-derived-types branch November 14, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Exclusion constraints, row guards and other constraint-like objects bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL severity/high Wrong results, crash or failed writes in a realistic scenario silent Answers wrongly without throwing; the fix ships as a minor, never a patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A declaration on a concrete TPC root reaches the root's table only: the derived tables get no constraint, in silence

1 participant