Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.
MIT License
134 stars 51 forks source link

TypeError: HistoryEvent.__init__() missing 4 positional arguments error occurs if app uses WebPubSub extension #415

Open hossam-nasr opened 1 year ago

hossam-nasr commented 1 year ago

There is a bug that sometimes occurs in which running any orchestrator in a DF node app will fail with an error saying "Exception: TypeError: HistoryEvent.init() missing 4 required positional arguments: 'EventType', 'EventId', 'IsPlayed', and 'Timestamp'" as below:

TypeError: HistoryEvent.__init__() missing 4 required positional arguments: 'EventType', 'EventId', 'IsPlayed', and 'Timestamp'
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 458, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
  File "C:\Python310\lib\concurrent\futures\thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 701, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper      
    result = function(**args)
  File "C:\Users\hossamnasr\ms\azure\test-functions\pystein-durable\.venv\lib\site-packages\azure\durable_functions\orchestrator.py", line 69, in handle
    return Orchestrator(fn).handle(DurableOrchestrationContext.from_json(context_body))
  File "C:\Users\hossamnasr\ms\azure\test-functions\pystein-durable\.venv\lib\site-packages\azure\durable_functions\models\DurableOrchestrationContext.py", line 98, in from_json
    return cls(**json_dict)
  File "C:\Users\hossamnasr\ms\azure\test-functions\pystein-durable\.venv\lib\site-packages\azure\durable_functions\models\DurableOrchestrationContext.py", line 50, in __init__
    self._histories: List[HistoryEvent] = [HistoryEvent(**he) for he in history]       
  File "C:\Users\hossamnasr\ms\azure\test-functions\pystein-durable\.venv\lib\site-packages\azure\durable_functions\models\DurableOrchestrationContext.py", line 50, in <listcomp>
    self._histories: List[HistoryEvent] = [HistoryEvent(**he) for he in history]       
)

This occurs when:

  1. Using DF with the upcoming V2 programming model model (not yet public preview)
  2. Setting the EnableWorkerIndexing feature flag
  3. Adding the Microsoft.Azure.WebJobs.Extensions.WebPubSub extension to your .csproj file
  4. Using the WebPubSub extension in your application

See this larger issue for more details: https://github.com/Azure/azure-functions-durable-extension/issues/2338

hossam-nasr commented 1 year ago

cc @davidmrdavid

fchapelle-modjaw commented 1 year ago

I get this very same error when setting the flag EnableWorkerIndexing (not using WebPubSub). My current workaround is setting it blank.

davidmrdavid commented 1 year ago

@hossam-nasr: could you please provide guidance on how to deal with this ^. Thanks!

hossam-nasr commented 1 year ago

@fchapelle-modjaw Are you using extension bundles in your app? Extension bundles include WebPubSub by default, so this issue will still occur if setting the EnableWorkerIndexing flag with extension bundles. If you need the EnableWorkerIndexing flag, then please use an extensions.csproj file to load only the extensions that you need, instead of using extension bundles.

davidmrdavid commented 1 year ago

it's worth noting that EnableWorkerIndexing is also a preview feature as far as I'm concerned. @fchapelle-modjaw: just so we know, how did you encounter this setting? Did any of the tooling automatically set it for you?

fchapelle-modjaw commented 1 year ago

I guess it was added automatically by azure extension for vscode ? Not sure to be honnest.

My requirements.txt is pretty short :

azure-functions
azure-functions-durable
mysql-connector-python
hossam-nasr commented 1 year ago

@fchapelle-modjaw I'd say if you don't know why you have it set, then you don't need it, and it's okay to not set it.