Skip to content

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

Merged
merged 8 commits into from
Jul 27, 2021

Conversation

davidmrdavid
Copy link
Contributor

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.

@davidmrdavid davidmrdavid marked this pull request as draft March 26, 2021 19:24
@davidmrdavid davidmrdavid requested a review from alrod May 25, 2021 23:35
@davidmrdavid davidmrdavid marked this pull request as ready for review May 25, 2021 23:35
try {
if (result) {
if (result || (isDurableBinding && result != null)) {
Copy link
Member

@alrod alrod May 26, 2021

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.

Copy link
Contributor Author

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 activityTriggers, 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.

@davidmrdavid davidmrdavid requested a review from alrod June 1, 2021 22:41
Copy link
Member

@alrod alrod left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants