question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IQueryable<> does not utilize custom CosmosSerializer when serializing datetimeoffset

See original GitHub issue

Describe the bug When serializing DateTimeOffset values, they are formatted like “2023-04-11T21:24:36.6331736+00:00” instead of like “2023-04-11T21:24:36.6331736Z”, even though I have configured a custom json serializer which formats DateTimeOffset’s properly for cosmos range indexing.

The result is that filters based on datetimeoffsets are not accurate

image

To Reproduce Steps to reproduce the behavior. If you can include code snippets or links to repositories containing a repro of the issue that can helps us in detecting the scenario it would speed up the resolution.

Expected behavior ToQueryDefinition() should run values through the CosmosSerializer. This is also related to enums serialization issues (serializing as numbers).

Actual behavior DateTimeOffset formatted using some newtonsoft json serializer defaults

Environment summary SDK Version: 3.32.3 OS Version: Widows 10

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:25 (25 by maintainers)

github_iconTop GitHub Comments

1reaction
onionhammercommented, Apr 12, 2023

@ealsur valid concern re: backwards compatibility, but there needs to be some consideration for new implementers who, while implementing new applications using this SDK, may miss the subtle misbehavior between a string comparison and a date range comparison being done within Cosmos.

Perhaps this distinction should be added as a warning to the documentation, at the very least.

Many new .NET applications don’t mess around with DateTime objects anymore, since DateTimeOffset avoids any ambiguities around DateTimeKind, so this would be an immediate foot-gun built into the SDK that could be very difficult to notice. I would also not be surprised if many applications are simply wrong and implementors dont even realize their comparison is broken because it works 90% (or whatever percent) of the time.

1reaction
onionhammercommented, Apr 12, 2023

@ealsur I feel the resolution of that issue has stalled, and this could be resolved without that fix - it could also be worked-around BY that fix, but wouldn’t change the default behavior, which is to serialize dates in a format Cosmos itself does not understand as a date.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Text.Json custom serializer for CosmosDb ...
The issue was caused by the class hierarchy. Id was the only field coming from an underlying class, and System.Text.Json requires extra wotk ......
Read more >
CosmosClientOptions.Serializer Property
The client will use it to serialize or de-serialize user's cosmos request/responses. SDK owned types such as DatabaseProperties and ContainerProperties will ...
Read more >
Custom JSON serialization with Azure Cosmos DB SDK
This post explains how you can use custom JSON serializer settings with Cosmos DB using Newtonsoft JSON and System.Text.Json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found