fix: add a custom deserializer to TaskDefinition#6
Merged
cdavernas merged 1 commit intoserverlessworkflow:mainfrom Nov 12, 2025
Merged
Conversation
5e2b45e to
f683890
Compare
…ion bug This commit addresses two issues: 1. Fixed TaskDefinition deserialization conflict between Do and For tasks - Added custom deserializer to handle overlapping 'do' field - For tasks are now correctly identified by the presence of 'for' field - Prevents ForTaskDefinition from being incorrectly deserialized as DoTaskDefinition 2. Fixed ForLoopDefinition serde rename attribute - Changed rename from "emit" to "each" on the each field - Added unit test to validate the fix Signed-off-by: Armin Graf <arminhammer@gmail.com>
f683890 to
bdc8f31
Compare
cdavernas
approved these changes
Nov 12, 2025
Member
cdavernas
left a comment
There was a problem hiding this comment.
Looks great to me, thank you ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
This PR proposes fixes for two issues that I have run into that I would like to see addressed:
Issue 1:
In the official Serverless Workflows spec, it is possible to define Do and For type tasks. Both of these tasks have the
dokeyword in their definition. The example in the reference is:Unfortunately the TaskDefinition enum in
task.rsuses #[serde(untagged)], which causes issues when deserializing tasks that have overlapping fields, such as 'do' and 'for'.Serde will attempt to deserialize into each variant in order, and since both 'do' and 'for' tasks contain a 'do' field, this can lead to incorrect deserialization.
In the current code, because Do comes before For in the enum, a ForTaskDefinition will always be deserialized to a DoTaskDefinition, because Do it comes first in the list.
This PR adds a custom
DeserializerforTaskDefinition, which can handle the issue between For and Do. It first checks to see whetherforexists in the task definition, and matches aForTaskDefinitionif that is the case. Thedocase is placed at the end, so that collisions are avoided. Other task types should remain unaffected.I added unit tests to test that the fix works, and that the custom validator fixes the issue.
Issue 2:
There is a small bug in the ForLoopDefinition in
task.rs:"emit"should be"each". This typo causes deserialization to fail. This PR fixes the issue and the unit testtest_for_loop_definition_each_field_deserializationvalidates the bug and the fix.