Azure function, timer-triggered using Python V2 model - how to return HTTP response?

Amir Katz 80 Reputation points
2023-02-27T09:08:10.7266667+00:00

I have an Azure function using the Python V2 model (see code snippet below). It implements a timer trigger.

The development and deployment are done with CLI tools, 'az' and 'func'.

When using this development method (az+func), there is no 'settings.json' file for input/output bindings. Instead, the generated main function (in file 'function_app.py') uses Python decorators that define those.

I would like the function to return an HTTP response, but when I replaced the return type of None with a 'func.HttpResponse', I got this error:

Result: Failure Exception: RuntimeError: function 'QueueReaderTimer' without a $return binding returned a non-None value

I wonder whether it's even possible to add a return binding to a timer function and if yes, how.

The Integration page of the function does not allow any editing, as seen in this screenshot:2023-02-27 10_59_42-Window

Function code snippet:

@app.function_name(name='QueueReaderTimer')
@app.schedule(schedule=cron_schedule, arg_name='mytimer', run_on_startup=True, use_monitor=False)
def test_function(mytimer: func.TimerRequest, context: func.Context) -> None:
   ...my code here...
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2023-03-01T16:28:45.0633333+00:00

    Amir Katz Thank you for posting this question in Microsoft Q&A. You are correct, in new V2 model, we have decorator-based approach instead of functions.json file and the same has been described here.

    Regarding your question on Timer trigger, it is not possible to return "Http" output since it is not supported yet. Currently, Python V2 is in preview and only specific triggers, bindings and output are supported. Please review Triggers and Inputs table for more info: User's image

    For more examples, see Python V2 model Azure Functions triggers and bindings (preview) and in that, you can see return type as None for Timer trigger whereas for supported examples, return type as func.HttpResponse.
    User's image

    User's image

    I hope this helps with your question and let me know if you have any other questions. Would be happy to answer any. For any feedback related to this feature or product, feel free to submit directly to our product team via https://feedback.azure.com/d365community/forum/9df02822-f224-ec11-b6e6-000d3a4f0da0


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.