2

I have Azure Durable Function. It is mostly based on: https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-python-vscode

I'm trying to migrate reqular HTTP Trigger as Durable Function?

I have modified code to accept json in HTTP Start and Orchestrator Functions. However Activity Function cannot take in json. How to modify HelloActivity to accept json? Following line seems to cause issue.

def main(datajson: str) -> str:

HelloOrchestrator:

import logging
import json

import azure.functions as func
import azure.durable_functions as df


def orchestrator_function(context: df.DurableOrchestrationContext):

    # Take the json data from the DurableOrchestrationContext, which was passed during the invocation
    data = context._input
    data = json.loads(data)
    logging.info(f"Orchestrator: Input is: {data}")
    
    result1 = yield context.call_activity('HelloActivity', data)
    #result1 = yield context.call_activity('HelloActivity', "ThisWouldWork")

    return [result1]
    main = df.Orchestrator.create(orchestrator_function)

HelloActivity

import logging

def main(datajson: str) -> str:
    logging.info(f"Activity datajson :" + datajson)
    return f"Hello world"

Error:

Function 'HelloOrchestrator (Orchestrator)' failed with an error. Reason: Message: 
Activity function 'HelloActivity' failed:  TypeError: can only concatenate str (not 
"dict") to str 
 {"$type":"System.Exception, 
System.Private.CoreLib","ClassName":"System.Exception","Message":" TypeError: can only 
concatenate str (not \"dict\") to str","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException, 
1
  • 2
    Your error is with this line logging.info(f"Orchestrator: Input is: {data}"). Pass the original string (context._input) and not the dictionary object. Commented Nov 25, 2021 at 17:56

1 Answer 1

3

Thank you @John Hanley , For your suggestion Posting it as an answer to help other community .

Reason: Message:  Activity function 'HelloActivity' failed: 
TypeError: can only concatenate str (not  "dict") to str  ```

For the above error :

" Your error is with this line logging. info(f"Orchestrator: Input is: {data}"), Pass the original string (context._input) and not the dictionary object ."

For more information please refer this Blog .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.