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

How to use ExecuteStateTransactionAsync() #1266

Closed
koumdev opened this issue Apr 5, 2024 · 3 comments
Closed

How to use ExecuteStateTransactionAsync() #1266

koumdev opened this issue Apr 5, 2024 · 3 comments

Comments

@koumdev
Copy link

koumdev commented Apr 5, 2024

Ask your question here

Hello,

I'm trying to use ExecuteStateTransactionAsync() with Azure Cosmos DB state store, but it does not work. I keep getting "error while executing state transaction: transaction failed due to operation 0 which failed with status code 400" exception.

I tried exactly what is in the Dapr documentation in .NET here:

var random = new Random();
int orderId = random.Next(1, 1000);
var requests = new List<StateTransactionRequest>()
{
    new("order_1", JsonSerializer.SerializeToUtf8Bytes(orderId.ToString()), StateOperationType.Upsert)
};
await _daprClient.ExecuteStateTransactionAsync(STORE_NAME, requests, cancellationToken: cancellation);

I also tried it with PowerShell:

Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"operations": [{"operation":"upsert", "request": {"key": "order_1", "value": "250"}}, {"operation":"upsert", "request": {"key": "order_2", "value": "450"}}]}' -Uri 'http://localhost:3500/v1.0/state/statestorecosmos/transaction'

The documentation says that Azure Cosmos DB state store supports transactional operations.

What am I doing wrong?

Thanks!

@philliphoff
Copy link
Collaborator

@koumdev Did the PoserShell approach work, or did it return the same 400 error? If the latter, then that would point to a possible issue with the runtime or component rather than the .NET SDK. In that case, I might ask the question in the dapr/components-contrib repo which would be more familiar with Azure Cosmos DB.

@koumdev
Copy link
Author

koumdev commented Apr 11, 2024

@philliphoff thank you for your reply and sorry for posting in the wrong place. Yes, I get the same 400 error with PowerShell. I posted in the components repo here.

@philliphoff
Copy link
Collaborator

Closing this in favor of the components-contrib issue.

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

2 participants