fix: add a custom deserializer to TaskDefinition #6
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.