Skip to content

Fix delayed converter resolution for nullables#6453

Merged
NinoFloris merged 2 commits intonpgsql:mainfrom
NinoFloris:fix-delayed-converter-resolution
Mar 12, 2026
Merged

Fix delayed converter resolution for nullables#6453
NinoFloris merged 2 commits intonpgsql:mainfrom
NinoFloris:fix-delayed-converter-resolution

Conversation

@NinoFloris
Copy link
Member

Closes #6450

Copilot AI review requested due to automatic review settings February 18, 2026 19:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes an issue where delayed converter resolution for nullable arrays fails when null values precede non-null values. The problem occurred because null values in nullable arrays (e.g., DateTime?[]) were locking in the default type (timestamp), preventing subsequent non-null values that require a different type (timestamptz) from being properly resolved.

Changes:

  • Fixed NullableConverter to return null instead of the default resolution for null values, allowing array converter to continue looking for non-null values
  • Simplified ArrayConverter by removing special null handling (but introduces a regression)
  • Added test case to verify null values can precede non-null values in nullable arrays

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Npgsql/Internal/Converters/NullableConverter.cs Changed GetEffectiveResolution to return null for null values instead of getting default resolution, enabling delayed resolution
src/Npgsql/Internal/Converters/ArrayConverter.cs Removed special handling for null arrays and simplified switch statement structure (introduces bug for null arrays)
test/Npgsql.Tests/Types/DateTimeTests.cs Added test case verifying that null can precede non-null DateTimeKind.Utc values in DateTime?[] arrays

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 18, 2026 20:09
@NinoFloris NinoFloris force-pushed the fix-delayed-converter-resolution branch from 3ff2bc9 to d399a7c Compare February 18, 2026 20:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NinoFloris NinoFloris merged commit 013e771 into npgsql:main Mar 12, 2026
12 checks passed
NinoFloris added a commit that referenced this pull request Mar 12, 2026
NinoFloris added a commit that referenced this pull request Mar 12, 2026
NinoFloris added a commit that referenced this pull request Mar 12, 2026
@NinoFloris
Copy link
Member Author

Backported to 10.0.2 via 87e8b6a, 9.0.5 via cc8772d, and 8.0.9 via dbd9be9

@NinoFloris NinoFloris deleted the fix-delayed-converter-resolution branch March 12, 2026 06:02
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.

Return of the #4340. Error occured when writing to timestamptz from DateTime?[]

3 participants