Skip to content

Fix nullability metadata for PostgreSQL translations - #4134

Merged
roji merged 2 commits into
mainfrom
roji-translation-nullability-fixes
Nov 17, 2026
Merged

roji merged 2 commits into
mainfrom
roji-translation-nullability-fixes

Conversation

@roji

@roji roji commented Nov 17, 2026

Copy link
Copy Markdown
Member

Incorrect nullability metadata allows EF to remove required null compensation or add incorrect null checks, silently returning the wrong rows for several PostgreSQL translations.

Correct function metadata for range bounds, date parts, LTree common ancestors, and spatial accessors. Make array_remove propagate nullability only from its array argument. Represent array concatenation as a PostgreSQL-specific binary operator so it is nullable only when both operands are nullable, while preserving the existing || SQL.

DateInterval intersection/union result semantics remain separate in #4083.

Fixes #4084

Correct nullable range, date-part, LTree and spatial translations. Fix array_remove propagation and give array concatenation PostgreSQL-specific nullability handling.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 14:57
@roji
roji enabled auto-merge (squash) November 17, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The SQL translation change leaves an existing test baseline outdated, causing both sync and async variants of GroupBy_complex_key_aggregate_2 to fail their SQL assertions.

1 open issue
What changed in this PR

This PR corrects nullability metadata in PostgreSQL query translations so EF Core preserves required null compensation and returns the expected rows. It addresses #4084 while leaving DateInterval intersection and union semantics to #4083.

Changes:

  • Correct nullability for range bounds, date parts, LTree common ancestors, and spatial accessors.
  • Model array concatenation as a PostgreSQL-specific operator and correct array_remove null propagation.
  • Add regression tests and update affected SQL expectations.
File Description
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​Temporal/​DateTimeTranslationsNpgsqlTest.cs Tests month comparisons on infinite timestamps.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​RangeTranslationsTest.cs Tests empty and unbounded range bounds.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​LocalDateTranslationsTest.cs Tests month comparisons on infinite dates.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​DateIntervalTranslationsTest.cs Tests null bounds on unbounded date ranges.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​LTreeTranslationsTest.cs Tests null common-ancestor results.
test/​EFCore.PG.FunctionalTests/​Query/​SpatialQueryNpgsqlGeometryTest.cs Tests missing ordinates, empty endpoints, and invalid indexes.
test/​EFCore.PG.FunctionalTests/​Query/​PrimitiveCollectionsQueryNpgsqlTest.cs Tests array null semantics and updates date-part SQL.
src/​EFCore.PG/​Query/​NpgsqlSqlExpressionFactory.cs Adds type mapping for array concatenation.
src/​EFCore.PG/​Query/​Internal/​NpgsqlSqlNullabilityProcessor.cs Makes concatenation nullable only when both operands are nullable.
src/​EFCore.PG/​Query/​Internal/​NpgsqlQuerySqlGenerator.cs Emits `
src/​EFCore.PG/​Query/​Internal/​NpgsqlQueryableMethodTranslatingExpressionVisitor.cs Uses the array operator and corrects array_remove metadata.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlRangeTranslator.cs Corrects range-bound nullability.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlLTreeTranslator.cs Corrects common-ancestor nullability.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlDateTimeMemberTranslator.cs Corrects date-part nullability.
src/​EFCore.PG/​Query/​Expressions/​PgExpressionType.cs Defines the array-concatenation operator.
src/​EFCore.PG/​Query/​Expressions/​Internal/​PgBinaryExpression.cs Adds array-concatenation expression printing.
src/​EFCore.PG.NTS/​Query/​ExpressionTranslators/​Internal/​NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs Corrects indexed spatial-accessor nullability.
src/​EFCore.PG.NTS/​Query/​ExpressionTranslators/​Internal/​NpgsqlNetTopologySuiteMemberTranslatorPlugin.cs Corrects ordinate and endpoint nullability.
src/​EFCore.PG.NodaTime/​Query/​Internal/​NpgsqlNodaTimeMemberTranslatorPlugin.cs Corrects date-range bound and date-part nullability.

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:05
@roji
roji disabled auto-merge November 17, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the nullability metadata and array-concatenation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@roji
roji enabled auto-merge (squash) November 17, 2026 15:16
@roji
roji merged commit e7f561e into main Nov 17, 2026
16 checks passed
@roji
roji deleted the roji-translation-nullability-fixes branch November 17, 2026 15:27
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.

Several translations declare the wrong nullability, so !=, !(==) and == null drop or keep the wrong rows (same class as #3585)

2 participants