Skip to content

Commit 1f1305f

Browse files
authored
Allow for an output binding value of an invocation result to be null (#10698)
In a successful invocation, the output binding is now allowed to be null and will no longer throw an exception.
1 parent a1da8aa commit 1f1305f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<!-- Please add your release notes in the following format:
44
- My change description (#PR)
55
-->
6+
- Allow for an output binding value of an invocation result to be null (#10698)
67
- Updated dotnet-isolated worker to 1.0.12.
78
- [Corrected the path for the prelaunch app location.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2897)
8-
- [Added net9 prelaunch app.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2898)
9+
- [Added net9 prelaunch app.](https://github.com/Azure/azure-functions-dotnet-worker/pull/2898)

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,10 @@ private async Task<object> GetBindingDataAsync(ParameterBinding binding, string
10681068
case ParameterBindingType.Data:
10691069
// Data was transferred by the worker using RPC
10701070
return binding.Data.ToObject();
1071+
case ParameterBindingType.None:
1072+
return null;
10711073
default:
1072-
throw new InvalidOperationException("Unknown ParameterBindingType");
1074+
throw new InvalidOperationException($"Unknown ParameterBindingType of type {binding.RpcDataCase}");
10731075
}
10741076
}
10751077

test/WebJobs.Script.Tests/Workers/Rpc/GrpcWorkerChannelTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,20 @@ await TestHelpers.Await(() => GetInvocationLogs().Length == logLoop,
15461546
}
15471547
}
15481548

1549+
[Fact]
1550+
public async Task NullOutputBinding_DoesNotThrow()
1551+
{
1552+
await CreateDefaultWorkerChannel();
1553+
1554+
var invocationId = Guid.NewGuid();
1555+
var resultSource = new TaskCompletionSource<ScriptInvocationResult>();
1556+
ScriptInvocationContext scriptInvocationContext = GetTestScriptInvocationContext(invocationId, resultSource, logger: _logger);
1557+
await _workerChannel.SendInvocationRequest(scriptInvocationContext);
1558+
await _workerChannel.InvokeResponse(BuildSuccessfulInvocationResponseWithNullOutputBinding(invocationId.ToString()));
1559+
1560+
Assert.Equal(TaskStatus.RanToCompletion, resultSource.Task.Status);
1561+
}
1562+
15491563
private static IEnumerable<FunctionMetadata> GetTestFunctionsList(string runtime, bool addWorkerProperties = false)
15501564
{
15511565
return GetTestFunctionsList(runtime, numberOfFunctions: 2, addWorkerProperties);
@@ -1690,6 +1704,30 @@ private static InvocationResponse BuildSuccessfulInvocationResponse(string invoc
16901704
};
16911705
}
16921706

1707+
private InvocationResponse BuildSuccessfulInvocationResponseWithNullOutputBinding(string invocationId)
1708+
{
1709+
StatusResult statusResult = new StatusResult()
1710+
{
1711+
Status = StatusResult.Types.Status.Success
1712+
};
1713+
1714+
ParameterBinding parameterBinding = new ParameterBinding()
1715+
{
1716+
Name = "output1",
1717+
Data = null
1718+
};
1719+
1720+
InvocationResponse invocationResponse = new InvocationResponse()
1721+
{
1722+
InvocationId = invocationId == null ? "TestInvocationId" : invocationId,
1723+
Result = statusResult
1724+
};
1725+
1726+
invocationResponse.OutputData.Add(parameterBinding);
1727+
1728+
return invocationResponse;
1729+
}
1730+
16931731
private static FunctionMetadata BuildFunctionMetadataForHttpTrigger(string name, string language = null)
16941732
{
16951733
var functionMetadata = new FunctionMetadata() { Name = name, Language = language };

0 commit comments

Comments
 (0)