Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.
MIT License
136 stars 55 forks source link

DurableOrchestrationContext call_http does not work with string input #473

Open nickholt15 opened 10 months ago

nickholt15 commented 10 months ago

🐛 Describe the bug

There is a logical error in the DurableOrchestrationContext call_http method.

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

content is type hinted as a str, however it only works with dictionary input.

I noticed this error when turning on type checking within VS Code.

To satisfy the type checker, I tried piping the dictionary object through json.dumps(), but that led to an error during execution.

🤔 Expected behavior This should work with either dictionary or string input. It only works with dictionary input.

Steps to reproduce Construct an arbitrary payload with key-value pairs.

context.call_http(method='POST', content=payload, uri=my_uri) succeeds

context.call_http(method='POST', content=json.dumps(payload), uri=my_uri) fails

Line 239 is responsible for the error: https://github.com/Azure/azure-functions-durable-python/blob/dev/azure/durable_functions/models/DurableOrchestrationContext.py#L239

The line:

if content and content is not isinstance(content, str):

should instead be:

if content and not isinstance(content, str):

paulschroeder-tomtom commented 9 months ago

@nickholt15 Hey, I think I experienced the same problem: https://github.com/Azure/azure-functions-durable-python/issues/478 you might want to have a look for details.

I am a little afraid to mark mine as a duplicate of yours, since I guess MS will then discard mine and will not have a look at the details (which as I think are really helpful). So I ask you, if you might want to tag yours as a duplicate of mine?

LandyManderson commented 1 month ago

I just ran into this issue and am grateful you'd reported it with the explanation of what's happening.