[CosmosDB] Concurrency token isn't updated when an embedded entity is modified #26625
Labels
area-cosmos
area-save-changes
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
Include your code
A sample application which reproduces the issue is attached below. The project attempts to connect to a CosmosDB emulator running on the local computer. This problem scenario has not been tested against a real Azure CosmosDB account but similar behavior in an existing application has been observed there as well. The problem seems to be in EF Core itself.
The sample solution contains a container entity, a child entity and a DbContext-derived class acting as the context.
cosmosdb-nested-entities-issue.zip
Include provider and version information
EF Core version: 5.0.12
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Database provider version: 5.0.12
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.5
CosmosDB Emulator version: 2.14.2.0 (ed0413c7)
Operating system time zone settings: "UTC+02:00 Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"
Reproduction steps
Observed result
As seen from the console output of the program, the
ETag
value of theDummyContainer
entity is not updated correctly after the secondSaveChangesAsync
is called. An explicitReloadAsync
is required in order for the new value to be present in the entity's property.The following
DebugView
extract shows that before theReloadAsync
call, the updatedETag
value is available in the change tracker but for some reason or another the change does not "swim up" to the property:Furthermore, attempting to perform multiple
SaveChangesAsync
calls will result in a concurrency exception. Most likely in the second save call EF Core attempts to send the previousETag
value from the entity, and the CosmosDB emulator then correctly declines the action. EF Core then proceeds to operate correctly and throws the exception.The full exception stack trace is as follows:
Expected result
The expected outcome of the whole program is that there is no need to call
ReloadAsync
in order to update the entity'sETag
property. Furthermore, it is expected that consecutive
SaveChangesAsync
calls will not throw an exception.Further notes
This issue has been tested with Entity Framework 6.0.0 as well. Since I do not have Visual Studio 2022 installed I was forced to use the command line tools. The only difference seems to be that the
ETag
value after the secondSaveChangesAsync
is set to null or an empty string. I cannot debug the solution so I do not know for sure.Otherwise things like change tracker output remain the same with EF Core 6.0.0
The text was updated successfully, but these errors were encountered: