Skip to content

[Internal] Binary Encoding: Fixes DateTime Parsing Issue#5133

Merged
FabianMeiswinkel merged 7 commits intomasterfrom
users/kundadebdatta/5132_fix_date_parsing_in_binary_encoding
Apr 17, 2025
Merged

[Internal] Binary Encoding: Fixes DateTime Parsing Issue#5133
FabianMeiswinkel merged 7 commits intomasterfrom
users/kundadebdatta/5132_fix_date_parsing_in_binary_encoding

Conversation

@kundadebdatta
Copy link
Copy Markdown
Member

@kundadebdatta kundadebdatta commented Apr 15, 2025

Pull Request Template

Description

During some of the internal binary encoding opt-in customer workload validation, it was identified that when the cosmos .net SDK is initialized with binary encoding, and a date time field is persisted into a database, the value is getting converted and stored as in non-ISO format.

Cosmos Client Creation:

        Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, "True");
        string databaseName = "binary-encoding-db";
        string containerName = "binary-encoding-container";
        CosmosClientOptions clientOptions = new()
        {
            ConnectionMode = ConnectionMode.Direct,
            RequestTimeout = TimeSpan.FromSeconds(5000),
        };

        CosmosClient client = new CosmosClient(connectionString,
            clientOptions);

        ItemResponse<ToDoActivity> itemResponse = await container.CreateItemAsync(item);

Sample Data Saved in Container, when binary encoding is Disabled in the SDK:

Image

Sample Data Saved in Container, when binary encoding is Enabled in the SDK:

Image

This PR is fixing the above parsing gap. It appears that when a stream is sent to the backend in Text format, the backend does some formatting on the incoming stream, that converts DateTime fields into ISO 8601 format and stores it.

image

Per my analysis, when binary encoding is enabled, and the stream sent to backend is in Binary format, the backend doesn't do any extra formatting on the binary stream, and stores the stream as is. Therefore, the round-trip ("O", "o") format specifier in the SDK layer is ideal to keep the DateTime field preserved in ISO standard, when binary encoding is enabled,

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Closing issues

To automatically close an issue: closes #5132

@kundadebdatta kundadebdatta self-assigned this Apr 15, 2025
@kundadebdatta kundadebdatta added the BinaryEncoding binary encoding in .NET sdk label Apr 15, 2025
@kundadebdatta kundadebdatta marked this pull request as draft April 15, 2025 16:53
@kundadebdatta kundadebdatta marked this pull request as ready for review April 15, 2025 18:31
Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM - Thx

Copy link
Copy Markdown
Contributor

@sboshra sboshra left a comment

Choose a reason for hiding this comment

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

:shipit:

@kundadebdatta kundadebdatta added the auto-merge Enables automation to merge PRs label Apr 16, 2025
@FabianMeiswinkel FabianMeiswinkel merged commit 1848684 into master Apr 17, 2025
26 checks passed
@FabianMeiswinkel FabianMeiswinkel deleted the users/kundadebdatta/5132_fix_date_parsing_in_binary_encoding branch April 17, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Enables automation to merge PRs BinaryEncoding binary encoding in .NET sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binary Encoding - Analyze and Fix DateTime Parsing Issue with .NET SDK Item Operations

4 participants