Azure / azure-functions-python-worker

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

Timer trigger function results in output TypeError #1479

Closed gijs-romme closed 2 months ago

gijs-romme commented 2 months ago

Is your question related to a specific version? If so, please specify:

Version 2

What binding does your question apply to, if any? (e.g. Blob Trigger, Event Hub Binding, etc)

My function has a timer input trigger and a sendgrid output trigger.

Question

Yesterday I added a new function to my Azure function app. Since adding it, an already existing function (with the bindings described above) that I didn't change anything about doesn't run correctly anymore because it gives the following error: Result: Failure Exception: TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure_functions_worker.bindings.generic.GenericBinding'>" for Python type "NoneType" I see online that this error occurs when your function has an HTTP output binding and you don't return any HTTPResponse. However, mine doesn't have any HTTP binding. It's not supposed to return anything as you create the output by calling the 'set' method on the 'sendGridMessage' input argument. I already restore the function app back the its previous state by deleting the function that I added yesterday, but the error keeps on happening. Could anyone help me fix this issue please? It might also just be a bug...

Here's the function.json file content: { "scriptFile": "__init__.py", "bindings": [ { "name": "mytimer", "type": "timerTrigger", "direction": "in", "schedule": "0 0 * * * *" }, { "type": "sendGrid", "name": "sendGridMessage", "direction": "out", "apiKey": "SendGridAPIKey", "from": "..." } ], "retry": { "strategy": "exponentialBackoff", "maxRetryCount": 5, "minimumInterval": "00:00:10", "maximumInterval": "00:15:00" } }

And the relevant parts of my init.py file: def main(mytimer: func.TimerRequest, sendGridMessage: func.Out[str]) -> None: # noqa: F841 message = ... sendGridMessage.set(json.dumps(message)) logging.info('Function ran successfully.')

gavin-aguiar commented 2 months ago

@gijs-romme Can you try removing the return None or return just any string for your second function? Would you also be able to share your functionapp name or any previous invocation id?

rrr-michael-aquilina commented 2 months ago

I'm facing a similar issue in the last couple days, code did not change but the same error started to appear on eventgrid functions

benyahiaabdelmonem commented 2 months ago

Hello, I have the same issue. Errors appeard without changing any thing in the code. I still have the same error even when I modified the code in light version. This is the main in the init.py : def main(sqlChanges) -> None: logging.info(sqlChanges) And this is the binding :

{ "scriptFile": "init.py", "bindings": [ { "name": "sqlChanges", "type": "sqlTrigger", "direction": "in", "tableName": "notif.go_nogo", "connectionStringSetting": "SqlConnectionString" } ] }

Thank you for your help

claria commented 2 months ago

Same here on very different trigger types. What worked for me as a workaround was changing the return type to "-> str" and always return '' instead of a plain return / return None.

vegarvi commented 2 months ago

We experience the same issue without any change in the code

claria commented 2 months ago

To give a bit more details:

We are running around 20-30 functionapps which are python based. Some of them are written in v2 style some of them in v1 style.

Please take that issue serious!

ArmandasB commented 2 months ago

I encountered a similar problem with an SQL trigger after deployment yesterday with an unrelated update. It appears that returning an empty string provides a workaround.

PhilippePaulos commented 2 months ago

Same problem with Timer triggers. Started to happen when redeploying the function app (v1) without any code changes

gijs-romme commented 2 months ago

@gijs-romme Can you try removing the return None or return just any string for your second function? Would you also be able to share your functionapp name or any previous invocation id?

The 'return None' originally wasn't there, so that doesn't help. Just returning any string does fix the issue however! Thank you so much!

If it still helps: I'm not sure where to get the invocation ID, but I would expect it's the ID that's visible in this line in the 'Monitor' tab? Executing 'Functions.FunctionName' (Reason='Timer fired at 2024-04-18T12:00:00.0048481+00:00', Id=4fcf8c50-92fd-4785-9427-7997455838f3)

claria commented 2 months ago

Hi,

in the meantime i removed all the added return "" statements and fixed the host version to an old version that was used a couple of days ago and this is working as well:

In Powershell: az functionapp config set --name xxxxxxxxxxxxxx --resource-group xxxxxxxx --linux-fx-version '"DOCKER|mcr.microsoft.com/azure-functions/python:4.31.1.1-python3.9-appservice"'

The issue sounds very related to https://github.com/Azure/azure-functions-durable-python/issues/401

gavin-aguiar commented 2 months ago

Apologies for this error. We have fixed this issue and are in process of releasing a new runtime version. The fix will be in runtime version 4.33.2

abdulniyaspm commented 2 months ago

@gavin-aguiar Thank you for fixing this. I am also facing this issue in my time trigger based azure function(without any code change). I am trying to understand if this fix(4.33.2) will be automatically available in our runtime or do I need to make any changes on the azure function side to upgrade to 4.33.2?

gavin-aguiar commented 2 months ago

@abdulniyaspm You would just need to restart your functionapp to pick up the latest runtime version.

benyahiaabdelmonem commented 2 months ago

@gavin-aguiar Thank you for your answer but despite restarting my functionapp I still have the old version of runtime 4.33.1.1

gavin-aguiar commented 2 months ago

@benyahiaabdelmonem we have finished deploying this fix for dedicated function apps yesterday. Consumption apps are in progress. So if you have a non-consumption function app, you should be able to get the latest runtime version by restarting.