Skip to content

Commit

Permalink
Fix issue where null timer summary breaks codec (#405)
Browse files Browse the repository at this point in the history
Fixes #400
  • Loading branch information
cretz authored Feb 3, 2025
1 parent 69dfe5a commit 7b92674
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Temporalio/Worker/WorkflowCodecHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ await EncodeAsync(
}
break;
case WorkflowCommand.VariantOneofCase.StartTimer:
await EncodeAsync(codec, cmd.StartTimer.Summary).ConfigureAwait(false);
if (cmd.StartTimer.Summary != null)
{
await EncodeAsync(codec, cmd.StartTimer.Summary).ConfigureAwait(false);
}
break;
case WorkflowCommand.VariantOneofCase.UpdateResponse:
if (cmd.UpdateResponse.Completed is { } updateCompleted)
Expand Down
20 changes: 20 additions & 0 deletions tests/Temporalio.Tests/Worker/WorkflowCodecHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ await CreateAndVisitPayload(new(), act, async (ctx, payload) =>
});
}

[Fact]
public async Task EncodeAsync_AllPayloads_WorksWithNull()
{
// For every singular Payload field, we are going to set it to null and ensure it can still
// encode. This is to prevent regression since we missed that sometimes we are not checking
// for null in WorkflowCodecHelper.
var comp = new WorkflowActivationCompletion();
var codec = new MarkerPayloadCodec();
await CreateAndVisitPayload(new(), comp, async (ctx, payload) =>
{
var (msg, prop) = ctx.PropertyPath.Last();
var propInfo = msg.GetType().GetProperty(prop);
if (propInfo?.PropertyType == typeof(Payload))
{
propInfo.SetValue(msg, null);
await WorkflowCodecHelper.EncodeAsync(codec, comp);
}
});
}

// Creates payloads as needed, null context if already seen
private static async Task CreateAndVisitPayload(
PayloadVisitContext ctx, IMessage current, Func<PayloadVisitContext, Func<Payload>, Task> visitor)
Expand Down

0 comments on commit 7b92674

Please sign in to comment.