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

[State CosmosDB] Continuation token returned by QueryStateAsync() is invalid #3400

Closed
koumdev opened this issue Apr 11, 2024 · 3 comments
Closed
Labels
kind/bug Something isn't working stale triaged/unresolved wontfix This will not be worked on

Comments

@koumdev
Copy link

koumdev commented Apr 11, 2024

Hi,

I'm using Azure Cosmos DB state store and the QueryStateAsync() method. I want to get all of my data and used var query = "{\"filter\": {}}", but I run into an exception ("state store statestorecosmos query failed: context canceled") if my database has more than 999 rows. I then tried to use pagination, but I'm having unexpected behaviors with the returned continuation token.

Expected Behavior

If I have let's say 500 records in my container. I request 100 records. The token returned by QueryStateAsync() should allow me to read the next 100 records, and so on.

Actual Behavior

The token returned by QueryStateAsync() after retrieving the first 100 records is empty, so if I supply that in the query I get the same exact 100 records as before. I can't continue reading the data.

Steps to Reproduce the Problem

Using the .NET SDK:

var query = "{\"filter\": {}, \"page\": {\"limit\": 100}}";
var employeesResponse = await _daprClient.QueryStateAsync<Employee>(STORE_NAME, query, cancellationToken: cancellation);
// employeesResponse contains the first 100 records as expected

var paginationToken = employeesResponse.Token;
// Have to modify the token to escape the quotes first
...

query = $"{{\"filter\": {{}}, \"page\": {{\"limit\": 100, \"token\": {paginationToken}}}}}";
employeesResponse = await _daprClient.QueryStateAsync<Employee>(STORE_NAME, query, cancellationToken: cancellation);
// Should return the next 100 records, but doesn't because the token is empty. It returns the same 100 records returned previously

Or going directly to the API to just get 1 record at a time using this PowerShell script:

$firstResponse = Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"filter": {}, "page": { "limit": 1}}' -Uri 'http://localhost:3500/v1.0-alpha1/state/statestorecosmos/query'

write-host "First results"
write-host $firstResponse.results

$token = $firstResponse.token
write-host "First results token: $token."

$query = '{"filter": {}, "page": { "limit": 1, "token": "' + $token + '"}}'
write-host "Next query: $query."

$secondResponse = Invoke-RestMethod -Method Post -ContentType 'application/json' -Body $query -Uri 'http://localhost:3500/v1.0-alpha1/state/statestorecosmos/query'

write-host "Second results"
write-host $secondResponse.results

$token2 = $secondResponse.token
write-host "Second results token: $token2."

You'll notice that the key in the result of the first query is the same as the one from the second query, so it's returning the same record.

Additional Remarks

From the component code it looks like there is a bug, the limit is never forwarded to Cosmos DB. It is only used to return a subset of the result. Therefore the component is actually reading the default page size. The token returned by the component, if returned, causes unexpected behaviors.

I'm using Dapr version 1.13.0.

Thanks!

@berndverst
Copy link
Member

berndverst commented Apr 12, 2024

Query API is Alpha and unsupported. We are not currently planning to advance the Query API due to several significant design flaws, creating inconsistencies in experience across components and also a maintenance and support nightmare.

Additionally, the CosmosDB Go SDK we are using does not have native Query support and our attempt to implement this is extremely limited and error prone. Certain features of the Dapr Query API interface cannot currently be supported by our Cosmos DB implementation.

The Dotnet CosmosDB SDK as a lot of features which the Go SDK does not have. We have spoken to the CosmosDB team and the Azure SDK for Go team extensively, but not much can be done here until the CosmosDB team expands the capabilities of other SDKs.

Please consider using a Cosmos DB SDK with Query support directly for querying.

@berndverst berndverst added wontfix This will not be worked on triaged/unresolved labels Apr 12, 2024
Copy link

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 12, 2024
Copy link

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working stale triaged/unresolved wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants