dapr / dapr/components-contrib

[State CosmosDB] Preserve property order

Open
#3,373 2 comments 0 reactions 0 assignees View on GitHub
help wanted kind/enhancement size/XS
Dominant language
Go
Stars
602
Forks
580
Avg merge
4d 9h
Merged PRs (30d)
6

Description

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:

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

Is stored in the state store, _get state_ should return:

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

## Actual Behavior
When the value:

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

Is stored in the state store, _get state_ will _randomly_ return either:

```json
{
"$type": "some-type",
"value": "some-value"
}
```
or
```json
{
"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

Contributor guide

Open the contributing guide

Research direction

Start by locating the state.azure.cosmosdb component and trace its get-state read path. Reproduce the issue by storing the provided JSON and reading it repeatedly, then verify that the returned JSON preserves the original property order and that the component's tests cover this behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, go
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.