Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
331 stars 100 forks source link

Python language worker doesn't allow nill data with Dapr Cron Binding Trigger #1316

Closed ASHIQUEMD closed 2 months ago

ASHIQUEMD commented 9 months ago

Investigative information

Please provide the following:

Repro steps

Provide the steps required to reproduce the problem:

Create an azure function using Python Language and follow the steps mentioned in Readme.

Once you run the app, you will see an exception Exception: AttributeError: 'NoneType' object has no attribute 'type'. This exception occurs at this line in Python language worker.

This azure function app is supposed to be triggered by Dapr cron trigger every 10 second and it should log the message. However, Python language worker expects trigger data in all kinds of trigger. But Dapr cron binding doesn't send any data as part of trigger request, reason being it's a timer trigger.

Expected behavior

Provide a description of the expected behavior.

Python language worker should not expect trigger data in all triggers. In case of Dapr Cron binding trigger, it will not receive any request body, and it is by design from Dapr. Azure function app should get trigger based on the cron expression defined in Dapr cron binding component.

Actual behavior

Provide a description of the actual behavior observed.

Python language worker always expects a request body with trigger, that is not the case with Dapr Cron binding trigger. Dapr Cron binding trigger will simply call the app without any request body, so the data will be nil in this case.

Known workarounds

Provide a description of any known workarounds.

Contents of the requirements.txt file:

Provide the requirements.txt file to help us find out module related issues.
azure-functions

Related information

Provide any related information
# __init__.py

import datetime
import logging
import azure.functions as func

def main(triggerData) -> None:
    logging.info(f"Invoked by Dapr cron binding trigger: Hello, World! The time is {datetime.datetime.now()}")
# requirements.txt
azure-functions
# function.json
{
  "bindings": [
    {
      "type": "daprBindingTrigger",
      "bindingName": "scheduled",
      "name": "triggerData",
      "direction": "in"
    }
  ]
}