dapr / dapr/dotnet-sdk

Proposal: Add TryGetStateAsync method for non-actor state management operations

Open
#1,178 3 comments 0 reactions 1 assignee Claimed by @WhitWaldo View on GitHub
area/client/state
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
2d 1h
Merged PRs (30d)
6

Description

## Describe the proposal
When accessing a state store from a non-actor, there exists a `GetStateAsync` method. Unfortunately, if the key doesn't exist, this returns a `default(T)`, which, depending on the type of T doesn't necessarily tell you much about whether the state actually exists or not.

When accessing state from an Actor, there exists, a `TryGetStateAsync` which addresses this very problem since it returns a `ConditionalValue`, indicating whether the key exists or not.

I would like to propose that `TryGetStateAsync` be added to the non-actor state store API. It should return a `ConditionalValue` like that of the actor API. Most importantly, it fills a gap in the API right now in that there appears to be no definite way to confirm that a given key otherwise exists or not.

I'd be happy to contribute a PR, if this is an acceptable addition.

### Proposed breaking change
Today, `ConditionalValue` exists only in Dapr.Actors. To avoid having two identical types, this should be refactored out to a more common project like `Dapr.Client`.

Should be it - this looks to just be an issue in how the .NET API works and I don't see that it requires any changes to the sidecar itself.

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.