azure-functions-powershell-worker icon indicating copy to clipboard operation
azure-functions-powershell-worker copied to clipboard

SendGrid error when used in durable Orchestrator function

Open GMedlin opened this issue 2 years ago • 1 comments

I'm not sure if I'm doing something wrong, but to test this issue I created a new function project. I added a durable http starter function, an orchestrator function, and the SendGrid function all using the command palette templates.

When I run this function locally and call the endpoint to kick off an orchestrator instance, the SendGrid function successfully sends an email. However, when the orchestrator does its "replay" immediately after that function executes, it generates an exception saying ERROR: Value cannot be null. (Parameter 'input'). I'm not sure how this is possible. It shouldn't be trying to execute again, since the replay should remember that it already did. Also, the 'input' (which for testing I just set to 'Hello') is definitely not null.

See codebelow and the attached error message.

I updated my Orchestrator run.ps1 to this:

param($Context)

Write-Host "Hello from SendGrid activity!"
Invoke-DurableActivity -FunctionName 'SendGrid' -Input 'Test'

My SendGrid run.ps1 is below:

param($email, $TriggerMetadata)

Push-OutputBinding -Name 'Message' -Value (@{
    subject = "Thanks for your order $($email)!"
    content = @(@{
        type = 'text/plain'
        value = "Hi, thanks for your order!"
    })
})

SendGrid's function.json (email addresses removed for privacy):

{
  "bindings": [
    {
      "type": "activityTrigger",
      "name": "email",
      "direction": "in"
    },
    {
      "type": "sendGrid",
      "name": "message",
      "direction": "out",
      "apiKey": "SEND_GRID_API_KEY",
      "from": "x",
      "to": "x",
      "subject": "Test"
    }
  ]
}

Error Message.txt

GMedlin avatar May 02 '23 00:05 GMedlin

I've tried a couple of workarounds. I can use try/catch to catch the error that's caused by the 2nd/replay execution of the SendGrid function. The downside is I won't be aware of a legit error. The other thing I've tried successfully is calling SendGrid using its REST API in a function rather than using the output binding.

GMedlin avatar May 02 '23 02:05 GMedlin