Skip to content

Implement IFormattable on NpgsqlRange<T> and format bounds with invariant culture (#6730) - #6763

Open
lqkhanh295 wants to merge 1 commit into
npgsql:mainfrom
lqkhanh295:fix/npgsql-range-to-string-culture
Open

lqkhanh295 wants to merge 1 commit into
npgsql:mainfrom
lqkhanh295:fix/npgsql-range-to-string-culture

Conversation

@lqkhanh295

Copy link
Copy Markdown

Fixes #6730.

Problem

When converting an NpgsqlRange<T> to string under non-invariant cultures (e.g., de-DE or other cultures where comma is used as the decimal separator), numeric bounds are formatted with commas instead of decimal points (e.g., [1,5,2,25) instead of [1.5,2.25)).
When this string literal is sent to PostgreSQL (e.g., via EF Core parameter logging or parsing), PostgreSQL fails with:

malformed range literal: "[1,5,2,25)"
DETAIL: Too many commas.

Additionally, date and time bounds formatted under locale-specific patterns may not conform to standard ISO formats expected by PostgreSQL.

Solution

  1. Implement IFormattable on NpgsqlRange<T> with ToString(string? format, IFormatProvider? formatProvider).
  2. Ensure parameterless ToString() defaults to CultureInfo.InvariantCulture.
  3. Format DateTime, DateOnly, and DateTimeOffset bounds using standard ISO 8601 patterns when format is null/empty.
  4. Pass the format provider through to bound values if they implement IFormattable.
  5. Register the new public API method in PublicAPI.Unshipped.txt.
  6. Add regression unit test ToString_under_non_invariant_culture validating decimal and date/time range string formatting under culture de-DE.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
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.

NpgsqlRange<T>.ToString() formats bounds with the current culture, so EF Core's ToQueryString() and parameter logs show range text PostgreSQL misreads

2 participants