Skip to content

Commit 7b92674

Browse files
authored
Fix issue where null timer summary breaks codec (#405)
Fixes #400
1 parent 69dfe5a commit 7b92674

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Temporalio/Worker/WorkflowCodecHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ await EncodeAsync(
193193
}
194194
break;
195195
case WorkflowCommand.VariantOneofCase.StartTimer:
196-
await EncodeAsync(codec, cmd.StartTimer.Summary).ConfigureAwait(false);
196+
if (cmd.StartTimer.Summary != null)
197+
{
198+
await EncodeAsync(codec, cmd.StartTimer.Summary).ConfigureAwait(false);
199+
}
197200
break;
198201
case WorkflowCommand.VariantOneofCase.UpdateResponse:
199202
if (cmd.UpdateResponse.Completed is { } updateCompleted)

tests/Temporalio.Tests/Worker/WorkflowCodecHelperTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ await CreateAndVisitPayload(new(), act, async (ctx, payload) =>
7878
});
7979
}
8080

81+
[Fact]
82+
public async Task EncodeAsync_AllPayloads_WorksWithNull()
83+
{
84+
// For every singular Payload field, we are going to set it to null and ensure it can still
85+
// encode. This is to prevent regression since we missed that sometimes we are not checking
86+
// for null in WorkflowCodecHelper.
87+
var comp = new WorkflowActivationCompletion();
88+
var codec = new MarkerPayloadCodec();
89+
await CreateAndVisitPayload(new(), comp, async (ctx, payload) =>
90+
{
91+
var (msg, prop) = ctx.PropertyPath.Last();
92+
var propInfo = msg.GetType().GetProperty(prop);
93+
if (propInfo?.PropertyType == typeof(Payload))
94+
{
95+
propInfo.SetValue(msg, null);
96+
await WorkflowCodecHelper.EncodeAsync(codec, comp);
97+
}
98+
});
99+
}
100+
81101
// Creates payloads as needed, null context if already seen
82102
private static async Task CreateAndVisitPayload(
83103
PayloadVisitContext ctx, IMessage current, Func<PayloadVisitContext, Func<Payload>, Task> visitor)

0 commit comments

Comments
 (0)