Skip to content

call_http json serializes regular str content.Β #478

@paulschroeder-tomtom

Description

@paulschroeder-tomtom

πŸ› Describe the bug
The call_http method of DurableOrchestrationContext json serializes regular str content.

πŸ€” Expected behavior
It should NOT json serialize regular str content, as the code suggests

β˜• Steps to reproduce

What Durable Functions patterns are you using, if any?

N/A

Any minimal reproducer we can use?

See: https://github.com/Azure/azure-functions-durable-python/blob/dev/azure/durable_functions/models/DurableOrchestrationContext.py#L239

The interesting block looks like:

 def call_http(self, method: str, uri: str, content: Optional[str] = None,
...
        if content and content is not isinstance(content, str):
            json_content = json.dumps(content)
        else:
            json_content = content

and this does not seem to be quite right. If content = "foo" the conditions after the if will evaluate as follows:

content and (content (is not) isinstance(content, str))     # "is not" binds stronger than "and"
Truthy (and "foo" (is not) True )
True and ("foo" (is not) True)
True and True
True

I guess what you wanted was:

        if content and not isinstance(content, str):
            json_content = json.dumps(content)
        else:
            json_content = content

But if content = [] this will result in json_content = [] (in oposition to json_content = "[]"), not sure if you would want that (at least I wouldnt). You might want to use something like this, instead:

        if not isinstance(content, str):
            try:
                json_content = json.dumps(content)
            except TypeError:
                json_content = content

Since None and [] might be desirable to put in content and are all json serializable (as null and [] resp.).

Are you running this locally or on Azure?

Both

⚑If deployed to Azure

We have access to a lot of telemetry that can help with investigations. Please provide as much of the following information as you can to help us investigate!

N/A

DF Version

v1.2.8

Metadata

Metadata

Assignees

Labels

P2Priority 2bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions