dapr / dapr/dotnet-sdk

State Store - Controlling state store storage format - Save Operation vs State Transaction

Open
#1,458 5 comments 0 reactions 0 assignees View on GitHub
area/client/state question
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
2d 1h
Merged PRs (30d)
6

Description

CLI version: 1.15.0-rc.3
Runtime version: 1.15.0-rc.8
Dapr.AspNetCore 1.14.0

State Store : Sqlite

## Saving state - SaveStateAsync vs ExecuteStateTransactionAsync

When saving state to a state store via the SDK, who decides the control over content-type of stored state ?
I would assume that `SaveStateAsync `and `ExecuteStateTransactionAsync` would offer the same support.
In the example below, is there anything the SDK does (differently) before building the StateItem "proto", since I get different results.

What level responsibility maps to this problem ?

**Levels**
- App (app code)
- SDK
- Dapr
- Component

Looking at the state store source, I'm getting the impression that it only looks att the value type of state item (not meta data) (see below).

```csharp
var meta = new Dictionary()
{
{ "contentType", "application/json" }
};

var id = Guid.NewGuid();

var newState = new SampleState(id, "test");
await dapr.SaveStateAsync(StateStore, $"{id}_save", newState, metadata: meta);

var stateOperation = new StateTransactionRequest(
key: $"{id}_trans",
value: JsonSerializer.SerializeToUtf8Bytes(newState, options: dapr.JsonSerializerOptions),
operationType: StateOperationType.Upsert,
metadata: meta);

await dapr.ExecuteStateTransactionAsync(StateStore, [stateOperation], metadata: meta);
```

### Sqllite Web View
![Image](https://github.com/user-attachments/assets/0e10db96-e468-41b1-93c4-e1b40067643d)

### State component
Sqlite State Store component [source](https://github.com/dapr/components-contrib/blob/main/state/sqlite/sqlite_dbaccess.go#L299) snippet.

```golang
// Encode the value
var requestValue string
byteArray, isBinary := req.Value.([]uint8)
if isBinary {
requestValue = base64.StdEncoding.EncodeToString(byteArray)
} else {
var bt []byte
bt, err = json.Marshal(req.Value)
if err != nil {
return err
}
requestValue = string(bt)
}
```
### Question

Could this be an issue ? - SDK or Component wise, or just expected behavior.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.