question

EmmettM-3733 avatar image
0 Votes"
EmmettM-3733 asked ChaitanyaNaykodiMSFT-9638 commented

Durable Entity Azure Functions can't get a return from Orchestrator using Python

I am used to using Http, Queue, and Blob functions, but recently discovered Durable Functions and recognized how powerful they could be to get updates from long running processes. I am using Python and I want to store the state in a Durable Entity so I don't keep just cycling over the same code over and over. There is unfortunately very little documentation on how to work with Durable Entities, especially in Python. I have even tried to read some C# code, but it hasn't helped much. The only example they provide is a simple Counter function that is called from the Client function, but I want to call it from the Orchestrator function. The only documentation I can find is here:

https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-entities?tabs=python

This guide says I can do it from the orchestrator, and here is the example they provide:

 def orchestrator_function(context: df.DurableOrchestrationContext):
     entityId = df.EntityId("Counter", "myCounter")
     current_value = yield context.call_entity(entityId, "get")
     if current_value < 10:
        context.signal_entity(entityId, "add", 1)
     return state

So following that documentation, I get the following error:

Exception: RuntimeError: function 'DurableFunctionsEntityPy' without a $return binding returned a non-None value

I do not have a "return" at all in my Entity Function. Here is all the code that is in there, it's just the sample right now because I'm just trying to get it to work once.

 import logging
 import json
 import azure.functions as func
 import azure.durable_functions as df
    
    
 def entity_function(context: df.DurableEntityContext):
    
     current_value = context.get_state(lambda: 0)
     operation = context.operation_name
     if operation == "add":
         amount = context.get_input()
         current_value += amount
         context.set_result(current_value)
     elif operation == "reset":
         current_value = 0
     elif operation == "get":
         context.set_result(current_value)
        
     context.set_state(current_value)
    
 main = df.Entity.create(entity_function)

I have tried using various outputs in the function.json for the Entity Function, but none work. If I make this the function.json file:

 {
   "scriptFile": "__init__.py",
   "bindings": [
     {
       "name": "context",
       "type": "entityTrigger",
       "direction": "in"
     },
     {
       "name" : "$return",
       "type" : "durableClient",
       "direction" : "out"
     }
   ]
 }

I get the following error:

@durablefunctionsentitypy@myCounter: Function 'durablefunctionsentitypy (Entity)' failed with an error. Reason: Internal error: System.ArgumentNullException: Value cannot be null. (Parameter 'name')

I have tried a lot of different alternatives to go in this output, and none work. My entity_function is very basic and just follows the example. Please let me know what I'm doing wrong!

On a side note, I'm also very confused by the "return state" part of the example code? Where is "state" ever defined? It just seems like they threw that in there without showing any way for someone to figure it out. If I just put "return state" in my code without defining it, obviously I'll get an error. I wish Microsoft spent a little more time working through these guides so they made sense!

Please help, I'm pulling my hair out, and I have a work project depending on me getting this done!


UPDATE I believe this error may be unrelated to my code. I cloned the below github and tried running it and I get the same error. Is it possibly related to the extensionBundle in the host.json file? Here is what mine looks like:

 {
   "version": "2.0",
   "logging": {
     "applicationInsights": {
       "samplingSettings": {
         "isEnabled": true,
         "excludedTypes": "Request"
       }
     }
   },
   "extensionBundle": {
     "id": "Microsoft.Azure.Functions.ExtensionBundle",
     "version": "[2.*, 3.0.0)"
   }
 }

https://github.com/Azure/azure-functions-durable-python/tree/dev/samples/counter_entity






azure-functions
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @EmmettM-3733, my sincere apologies for the delayed response here. Yes, you are correct the issue was related to to the extensionBundle in the host.json file. The issue has been fixed on the repo you referenced, David has merged a PR to update the host.json file. Thank you for posting the issue.
Please let us know if there any additional concerns. Thank you!


0 Votes 0 ·

0 Answers