Azure / azure-functions-dapr-extension

Extension for interacting with Dapr APIs from an Azure Function
MIT License
95 stars 33 forks source link

Error 'Microsoft.Azure.WebJobs.Extensions.Dapr: A 'value' parameter is required for save-state operations' in dotnet-isolated #161

Closed KaiWalter closed 9 months ago

KaiWalter commented 9 months ago

I recoded samples/dotnet-isolated-azurefunction/OutputBinding/StateOutputBinding.cs in my own sample https://github.com/KaiWalter/azure-functions-dapr-experimental/blob/main/dotnet-cs-v4/PostState.cs like

    public static class PostState
    {
        [Function(nameof(PostState))]
        [DaprStateOutput("statestore", Key = "{key}")]
        public static string Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "state/{key}")] HttpRequestData req,
            FunctionContext functionContext)
        {
            var log = functionContext.GetLogger(nameof(PostState));

            string requestBody = new StreamReader(req.Body).ReadToEnd();

            log.LogInformation(requestBody);

            return requestBody;
        }
    }

after already struggling with #151 and implementing the suggested workaround, independent whether I start with

dapr run --app-id statefunc --dapr-http-port 3501 --resources-path ./components -- func host start

or

dapr run --app-id statefunc --dapr-http-port 3501 --resources-path ./components -- func start

I get this error

== APP == Functions:
== APP ==
== APP ==       GetState: [GET] http://localhost:7071/api/state/{key}
== APP ==
== APP ==       PostState: [POST] http://localhost:7071/api/state/{key}
== APP ==
== APP == For detailed output, run func with --verbose flag.
== APP == [2023-10-02T12:35:06.748Z] Worker process started and initialized.
== APP == [2023-10-02T12:35:13.387Z] Executing 'Functions.PostState' (Reason='This function was programmatically called via the host APIs.', Id=8926b827-f497-41e0-9f2a-66f20f64053f)
== APP == [2023-10-02T12:35:13.534Z] {"message": "Hello World"}
== APP == [2023-10-02T12:35:13.623Z] Executed 'Functions.PostState' (Failed, Id=8926b827-f497-41e0-9f2a-66f20f64053f, Duration=263ms)
== APP == [2023-10-02T12:35:13.623Z] System.Private.CoreLib: Exception while executing function: Functions.PostState. Microsoft.Azure.WebJobs.Extensions.Dapr: A 'value' parameter is required for save-state operations. (Parameter 'parametersJson').
ASHIQUEMD commented 9 months ago

Hi @KaiWalter, Thank you for your question. For DaprStateOutput binding value is a required property, so the data that needs to be saved in state store should be enclosed in a value property.

Please see the documentation here for required properties of Dapr State Output binding.

Http trigger curl request:

curl --location 'http://localhost:7071/api/state/order' \
--header 'Content-Type: application/json' \
--data '{
    "value": {
        "orderId": "123"
    }
}'
KaiWalter commented 9 months ago

Thanks @ASHIQUEMD - my bad, I overlooked that detail. Sending the POST with a value parameter works.

### Save state
POST http://localhost:7071/api/state/hello

{
  "value":"Hello World"
}