dapr / components-contrib

Community driven, reusable components for distributed apps
Apache License 2.0
533 stars 468 forks source link

[State CosmosDB] Preserve property order #3373

Open RobertConanMcMillan opened 4 months ago

RobertConanMcMillan commented 4 months ago

When reading an entry from a CosmosDB backed state store, properties are returned in seemingly random order, often shuffled differently on each fetch.

This breaks System.Text.Json polymorphism, as the $type (or other delimiter) must be the first property read in an object.

Expected Behavior

The JSON should not be modified or altered, when read from the state store.

When the value:

{
    "$type": "some-type",
    "value": "some-value"
}

Is stored in the state store, get state should return:

{
    "$type": "some-type",
    "value": "some-value"
}

Actual Behavior

When the value:

{
    "$type": "some-type",
    "value": "some-value"
}

Is stored in the state store, get state will randomly return either:

{
    "$type": "some-type",
    "value": "some-value"
}

or

{
    "value": "some-value"
    "$type": "some-type"
}

Steps to Reproduce the Problem

  1. Store JSON value in state.azure.cosmosdb state store
  2. Read value from state store
  3. Compare JSON property order

Release Note

RELEASE NOTE: FIX CosmosDB state returns shuffled JSON

berndverst commented 4 months ago

The Dapr API does not make any guarantees about the ordering of fields. This is not part of our API contract @RobertConanMcMillan. Therefore I do not see this as a bug.

However, I'm happy to accept PRs.