Azure / azure-functions-durable-python

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

wait_for_external_event Task result adds double quotes within the result attribute #295

Open legendof-selda opened 3 years ago

legendof-selda commented 3 years ago

🐛 Raise Event adds " in result When we raise an event from an activity, when picked up by the orchestrator function double quotes are added in result attribute.

The Orchestration function

def orchestrator_function(context: df.DurableOrchestrationContext):
  result = yield context.call_activity("CheckData", "blob_name")
  approval_code = yield context.call_activity("AskApproval", {"email": email, "instance_id": context.instance_id})
  timeout_task = context.create_timer(expiration)
  approval_approved_task = context.wait_for_external_event("RequestApproved")
  approval_rejected_task = context.wait_for_external_event("RequestRejected")
  final_status = None
  winner = yield context.task_any([approval_approved_task, approval_rejected_task, timeout_task])
  if winner == approval_approved_task or winner == approval_rejected_task:
    approved = winner == approval_approved_task and approval_approved_task.result == approval_code
    if not timeout_task.is_completed:
      timeout_task.cancel()
  if approved:
    final_status = yield context.call_activity("ApproveBlobFile", blob)
  return [approval_code , result, final_status]

main = df.Orchestrator.create(orchestrator_function)

The ApprovalTrigger which is a QueueTrigger function

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

async def main(msg: func.QueueMessage, starter: str) -> None:
    logging.info('Python queue trigger function processed a queue item: %s',
                 msg.get_body().decode('utf-8'))
    client = df.DurableOrchestrationClient(starter)
    msg = msg.get_json()
    if msg["approval"] is True:
        event_name = "RequestApproved"
    else:
        event_name = "RequestRejected"
    await client.raise_event(instance_id=msg["instance_id"], event_name=event_name, event_data=msg["approval_code"])

And yes, in queue the double quotes are not being added. Its being added when the orchestrator receives the event.

🤔 Expected behavior approval_approved_task.result must give out result \'\' not \'\"\"\'. For now we can use approval_approved_task.result.replace('\"','') == approval_code

Steps to reproduce

What Durable Functions patterns are you using, if any? This is actually a sub orchestration function. The parent orchestration simply list all the files in the blob and runs this sub orchestration for each blob Try raising any event from an external df activity Its run locally. Will try to deploy to Azure soon and share the Orchestration instance ID with it.

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!

If you don't want to share your Function App or storage account name GitHub, please at least share the orchestration instance ID. Otherwise it's extremely difficult to look up information.

davidmrdavid commented 3 years ago

Hi @legendof-selda,

Thank you for reaching out! Yes, we've recently seen issues where strings appear to receive an extra set of quotes; although I haven't seen it in occur in the case of external events yet. I'm relieved to hear that there's a straightforward workaround though.

We're soon to plan for an upcoming release. So I'll look to add this as an issue to prioritize for then!