Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetStateAsync throws exception if key not found when using json contentType #999

Open
MargaretKrutikova opened this issue Dec 18, 2022 · 5 comments

Comments

@MargaretKrutikova
Copy link

MargaretKrutikova commented Dec 18, 2022

Ask your question here

I am using redis for state store component with RedisJSON module, and when getting state with contentType metadata set to application/json, method GetStateAsync on the dapr client throws the following exception if the key doesn't exist:

Error when trying to Retrieve ... with Id: ..."Error","@x":"Dapr.DaprException: 
State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
Grpc.Core.RpcException: Status(StatusCode=\"Internal\", Detail=\"fail to get <...> from state store local: redis: nil\")
   at Dapr.Client.DaprClientGrpc.GetStateAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)

Is this an intended behavior or more like a bug? When not using any metadata the return value from GetStateAsync is null with no exception thrown if the key doesn't exist.

Thanks!

@halspang
Copy link
Contributor

halspang commented Jan 6, 2023

@MargaretKrutikova - I think we're supposed to return null instead of erroring out. How exactly are you setting the metadata? The format of from state store local: redis: nil is concerning for me. It looks like something may not be set right in the actual request.

@MargaretKrutikova
Copy link
Author

I apologize for the late reply, this how we are doing it:

Dictionary<string, string> metadata = new() { { "contentType", "application/json" } };
var data = await daprClient.GetStateAsync<SomeData>(config.StoreName, dataId, metadata: metadata);

Is there anything we are missing here?

@robert2ship
Copy link

Hello,

I have the same problem.
I had to change in my code to explicitly set the content type to json, to support the query api.
And now I get the surprise of getting errors when keys not found...

Thanks!

@CormacLennon
Copy link

We have also started to get this issue, also after adding the "contentType", "application/json" metadata so we could use querying with redis

@kenchou
Copy link

kenchou commented Sep 6, 2024

I encountered the same issue.
I used image docker.io/redis/redis-stack-server:latest instead of the Redis pulled by dapr init to enable ReJSON.
When specifying metadata.contentType=application/json, it throws an error if the key does not exist.

I noticed that the message "fail to get test from state store statestore: redis: nil" is returned from Dapr's state service.

curl 'http://localhost:3500/v1.0/state/statestore/test' -v
* Host localhost:3500 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:3500...
* Connected to localhost (::1) port 3500
> GET /v1.0/state/statestore/test HTTP/1.1
> Host: localhost:3500
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 204 No Content
< Content-Type: text/plain; charset=utf-8
< Traceparent: 00-4f62151a9cfab3eeb5fc6bc0c4c4889f-50b6560d85adeb3e-01
< Date: Fri, 06 Sep 2024 04:33:06 GMT
<
* Connection #0 to host localhost left intact


curl 'http://localhost:3500/v1.0/state/statestore/test?metadata.contentType=application/json' -v
* Host localhost:3500 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:3500...
* Connected to localhost (::1) port 3500
> GET /v1.0/state/statestore/test?metadata.contentType=application/json HTTP/1.1
> Host: localhost:3500
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 500 Internal Server Error
< Content-Type: application/json
< Traceparent: 00-b6bf3bdefcded5578f8aebada999418d-0d819f29f861d7b8-01
< Date: Fri, 06 Sep 2024 04:33:40 GMT
< Content-Length: 98
<
* Connection #0 to host localhost left intact
{"errorCode":"ERR_STATE_GET","message":"fail to get test from state store statestore: redis: nil"}

@halspang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants