Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cosmos] ISO date time strings are not read back correctly from the database #25656

Closed
anttikes opened this issue Aug 23, 2021 · 4 comments · Fixed by #25741
Closed

[Cosmos] ISO date time strings are not read back correctly from the database #25656

anttikes opened this issue Aug 23, 2021 · 4 comments · Fixed by #25741
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@anttikes
Copy link

anttikes commented Aug 23, 2021

Include your code

A sample application which reproduces the various the scenarios is attached to this post. The project attempts to connect to a CosmosDB emulator running on the local computer. The problem scenario has not been tested against an Azure CosmosDB account.

EFCoreISODatesBug.zip

Include provider and version information

EF Core version: 5.0.9
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Database provider version: 5.0.9
Underlying Azure SDK version: 3.12.0
Target framework: .NET 5.0
Operating system: Windows 10 Enterprise (version "10.0.19043 Build 19043")
IDE: Visual Studio 2019 version 16.11.1
CosmosDB Emulator version: 2.14.1.0 (08dca53e)
Operating system time zone settings: "UTC+02:00 Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"

Reproduction steps

  1. Open up the sample application in Visual Studio
  2. Build it
  3. Run it

Expected result

Since the model uses a plain string as the property's type the expected behavior is that the strings are saved into CosmosDB as-is, and when they are read back they are still exactly the same as before.

Observed behavior

The items are written correctly to the CosmosDB container, and the content of the documents therein corresponds exactly to the expected outcome.

When the items are read back from CosmosDB then the ISODate property is formatted differently, and the time stamp has automatically been adjusted by the UTC offset. On my computer, the adjustment that is done to the time stamp looks incorrect as well:

Re-creating database

Writing new item to database '4617064c-382a-409c-8caa-d6e8f88471f2'
        - ISODate: '2021-08-23T06:23:40Z'

Writing new item to database '39d830c6-c486-49b9-8464-4892d81b89d5'
        - ISODate: '2021-08-23T06:23:40+00:00'

Writing new item to database '28f12faa-dedd-4b0d-ae28-f739f4ce2102'
        - ISODate: '2021-08-23T06:23:40+02:00'

Reading back item '4617064c-382a-409c-8caa-d6e8f88471f2'
        - ISODate: '08/23/2021 06:23:40'

Reading back item '39d830c6-c486-49b9-8464-4892d81b89d5'
        - ISODate: '08/23/2021 09:23:40'

Reading back item '28f12faa-dedd-4b0d-ae28-f739f4ce2102'
        - ISODate: '08/23/2021 07:23:40'

Output from 'dotnet --info'

.NET SDK (reflecting any global.json):
 Version:   5.0.400
 Commit:    d61950f9bf

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.400\

Host (useful for support):
  Version: 5.0.9
  Commit:  208e377a53

.NET SDKs installed:
  3.1.412 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.203 [C:\Program Files\dotnet\sdk]
  5.0.206 [C:\Program Files\dotnet\sdk]
  5.0.303 [C:\Program Files\dotnet\sdk]
  5.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
@ajcvickers
Copy link
Member

@anttikes This appears to be an issue with the underlying Cosmos API or the Cosmos database implementation itself. EF Core simply treats these values as strings; it never attempts to parse them as dates. I would suggest you fil an issue with Cosmos, possibly starting here: https://github.com/Azure/azure-cosmos-dotnet-v3

@anttikes
Copy link
Author

@ajcvickers Thank you for your investigation. I haver reported the issue to the Cosmos SDK repository that you linked. Hopefully they can figure it out.

I'll close this issue. If the Cosmos SDK team reports that the bug is in EF Core then I'll re-open it with whatever relevant details they can provide.

@AndriySvyryd
Copy link
Member

@anttikes You can work around this by calling
Storage.Internal.CosmosClientWrapper.Serializer.DateParseHandling = Newtonsoft.Json.DateParseHandling.None;

AndriySvyryd added a commit that referenced this issue Aug 27, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 27, 2021
@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Aug 27, 2021
AndriySvyryd added a commit that referenced this issue Aug 27, 2021
@anttikes
Copy link
Author

Thanks @AndriySvyryd for the tip. I think our team can afford to wait for the next release where your fix is included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants