-
Notifications
You must be signed in to change notification settings - Fork 44
Serialize falsy values for Durable Functions #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
try { | ||
if (result) { | ||
if (result || (isDurableBinding && result != null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isDurableBinding == true
the result
can be (0, false, undef, '') ? Can you please add a comment describing why it happens for durable but not for regular executions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, in durable bindings such as activityTrigger
s, the result can be 0, false, and "". This is because Durable Function activities are meant to be abstractions similar to regular function invocations, so the programming model should, in theory, allow for any output value that would be valid to return in regular JavaScript and is JSON serializable. This includes the values: 0, false, and ""
. This was also a behavior we used to have in the past, but it stopped working recently, as described here: Azure/azure-functions-durable-js#50
I've also expanded my comments in the PR to make this clearer :) Please let me know if there's anything else I can clarify!
As for serializing undefined
, I think that gets serialized as null
anyways. I can certainly write code to explicitly avoid serializing undefined
though. Please let me know if you would prefer I added that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please squash to one commit
Replaces: #364
Due to legacy behavior, falsy values ("", false, 0) in JS currently do not get serialized. We cannot patch this behavior without breaking some JS customers, but also leaving this behavior unpatched breaks Durable Functions. In this PR, I try to find a middle-ground by ensuring that falsy values get serialized only when returning to the Durable Functions output binding.