Skip to content

Commit

Permalink
Allow for an output binding value of an invocation result to be null (
Browse files Browse the repository at this point in the history
#10698)

In a successful invocation, the output binding is now allowed to be null and will no longer throw an exception.
  • Loading branch information
satvu authored Dec 19, 2024
1 parent a1da8aa commit 1f1305f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Please add your release notes in the following format:
- My change description (#PR)
-->
- Allow for an output binding value of an invocation result to be null (#10698)
- Updated dotnet-isolated worker to 1.0.12.
- [Corrected the path for the prelaunch app location.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2897)
- [Added net9 prelaunch app.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2898)
- [Added net9 prelaunch app.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2898)
4 changes: 3 additions & 1 deletion src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,10 @@ private async Task<object> GetBindingDataAsync(ParameterBinding binding, string
case ParameterBindingType.Data:
// Data was transferred by the worker using RPC
return binding.Data.ToObject();
case ParameterBindingType.None:
return null;
default:
throw new InvalidOperationException("Unknown ParameterBindingType");
throw new InvalidOperationException($"Unknown ParameterBindingType of type {binding.RpcDataCase}");
}
}

Expand Down
38 changes: 38 additions & 0 deletions test/WebJobs.Script.Tests/Workers/Rpc/GrpcWorkerChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,20 @@ await TestHelpers.Await(() => GetInvocationLogs().Length == logLoop,
}
}

[Fact]
public async Task NullOutputBinding_DoesNotThrow()
{
await CreateDefaultWorkerChannel();

var invocationId = Guid.NewGuid();
var resultSource = new TaskCompletionSource<ScriptInvocationResult>();
ScriptInvocationContext scriptInvocationContext = GetTestScriptInvocationContext(invocationId, resultSource, logger: _logger);
await _workerChannel.SendInvocationRequest(scriptInvocationContext);
await _workerChannel.InvokeResponse(BuildSuccessfulInvocationResponseWithNullOutputBinding(invocationId.ToString()));

Assert.Equal(TaskStatus.RanToCompletion, resultSource.Task.Status);
}

private static IEnumerable<FunctionMetadata> GetTestFunctionsList(string runtime, bool addWorkerProperties = false)
{
return GetTestFunctionsList(runtime, numberOfFunctions: 2, addWorkerProperties);
Expand Down Expand Up @@ -1690,6 +1704,30 @@ private static InvocationResponse BuildSuccessfulInvocationResponse(string invoc
};
}

private InvocationResponse BuildSuccessfulInvocationResponseWithNullOutputBinding(string invocationId)
{
StatusResult statusResult = new StatusResult()
{
Status = StatusResult.Types.Status.Success
};

ParameterBinding parameterBinding = new ParameterBinding()
{
Name = "output1",
Data = null
};

InvocationResponse invocationResponse = new InvocationResponse()
{
InvocationId = invocationId == null ? "TestInvocationId" : invocationId,
Result = statusResult
};

invocationResponse.OutputData.Add(parameterBinding);

return invocationResponse;
}

private static FunctionMetadata BuildFunctionMetadataForHttpTrigger(string name, string language = null)
{
var functionMetadata = new FunctionMetadata() { Name = name, Language = language };
Expand Down

0 comments on commit 1f1305f

Please sign in to comment.