Skip to content

Cosmos datetime fixed width - #39131

Open
mohammedwed wants to merge 4 commits into
dotnet:mainfrom
mohammedwed:cosmos-datetime-fixed-width
Open

mohammedwed wants to merge 4 commits into
dotnet:mainfrom
mohammedwed:cosmos-datetime-fixed-width

Conversation

@mohammedwed

Copy link
Copy Markdown
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Fixes #39113

- Fall back to Cosmos SDK serialization when parameter values do not match the mapping type
- Preserve default SDK handling for parameter values incompatible with configured type mappings

Fixes dotnet#39113
Copilot AI balanced review requested due to automatic review settings September 30, 2026 10:06
@mohammedwed
mohammedwed requested a review from a team as a code owner September 30, 2026 10:06

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mohammedwed

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="veraxity.dev"

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.

Copilot review overview

🟡 Changes recommended

Legacy Cosmos documents remain incompatible with new parameters, and several shared JSON assertions are currently broken.

Review effort: Balanced
Findings: 3 High severity

Open (3)

Comment thread src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
Comment on lines 30 to +31
public override void ToJsonTyped(Utf8JsonWriter writer, DateTime value)
=> writer.WriteStringValue(value);

=> writer.WriteStringValue(value.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture));
Comment thread test/EFCore.Specification.Tests/JsonTypesTestBase.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 16:38

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

🔵 Needs a closer look

The shared writer changes unrelated providers and breaks existing SQL Server JSON baselines, while legacy-format compatibility remains untested.

1 open finding
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add regression coverage for reading legacy short-form dates

test/​EFCore.Cosmos.FunctionalTests/​Query/​AdHocMiscellaneousQueryCosmosTest.cs:197

This regression test only inserts documents through the new writer, so it does not verify that legacy documents containing the short form (for example, "2026-01-01T00:00:00Z") remain readable. The provider-independent JSON expectations were changed away from that form, leaving the compatibility claim from the review thread uncovered. Seed one document as raw legacy JSON (the existing AdHocCosmosTestHelpers.CreateCustomEntityHelperAsync supports this) and assert it materializes correctly.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

#region 39113

[Fact]
public virtual async Task DateTime_with_and_without_fractional_seconds_orders_and_filters_correctly()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a test that inserts datetime using the old format (by using the SDK directly) and then asserts that it's still materialized correctly both in entity instances and in projections

}

[Theory, InlineData("0001-01-01T00:00:00.0000000", """{"Prop":"0001-01-01T00:00:00"}"""),
[Theory, InlineData("0001-01-01T00:00:00.0000000", """{"Prop":"0001-01-01T00:00:00.0000000"}"""),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also update all the affected SQL Server baselines

Comment on lines +27 to +28


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extra whitespace

public override void ToJsonTyped(Utf8JsonWriter writer, DateTime value)
=> writer.WriteStringValue(value);

=> writer.WriteStringValue(value.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Allow the format to be specified in a public constructor. This would allow to use previous behavior if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cosmos DB: DateTime serialization format causing errors in ordering and filtering

3 participants