[BUG] FastAPI exception handler only catches exact exceptions
Maintainer antworten meist innerhalb von 2 Tagen
@EvanR-Dev arbeitet bereits daran.
Seit 05.12.2023.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
Investigative information
Please provide the following:
- Timestamp: Nov 22, 2023
- Function App name: running locally (reproduction of a production issue)
- Function name(s) (as appropriate): see above
- Core Tools version: ❯ func --version: 4.0.5455
Repro steps
Provide the steps required to reproduce the problem:
I'm using the AsgiMiddleware to wrap a FastApi app. If I add an exception_handler for Exception, then specific errors like ZeroDivisionError are not caught when running with func start, however, it works if I use uvicorn to run the app instead of func start. Please see https://github.com/ashic/azfn-fastapi-demo/blob/main/src/azfn_fastapi_demo/main.py
The main function is here:
from fastapi import FastAPI, Body, Response
from fastapi.responses import JSONResponse
import azure.functions as func
app = FastAPI()
@app.exception_handler(Exception)
async def catch_all(req, e:Exception):
return JSONResponse("Catch all handler")
# @app.exception_handler(ZeroDivisionError)
# async def zero_handler(req, e:ZeroDivisionError):
# return JSONResponse("Zero handler")
@app.post("/test")
async def test():
a = 20 / 0
return {
'content': "Hello"
}
main = func.AsgiMiddleware(app).main
If I remove the comments on the ZeroDivisionError handler, then running with func start cathes the divide by zero exception. However, with the code as is, when running with uvicorn, the Exception handler catches is, but running with func start, doesn't.
I use scripts/run-local.sh to run via uvicorn and scripts/run-local-az.sh to run with the azure function host.
Expected behavior
Provide a description of the expected behavior.
When running with func start, an Exception handler should catch all exceptions. The behaviour should be the same as when running with uvicorn.
Actual behavior
Provide a description of the actual behavior observed.
The behaviour differs from running with uvicorn. Only specific exceptions are caught.
Known workarounds
Provide a description of any known workarounds.
Other than writing a handler for every possible error, there doesn't seem to be one.
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
azure-functions==1.17.0
fastapi==0.104.1
uvicorn==0.24.0.post1
- Vorherrschende Sprache
- Python
- Sterne
- 357
- Forks
- 118
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Azure/azure-functions-python-worker
-
[Bug] ASGI cookie conversion serializes an absent Domain attribute and breaks __Host- cookiesEvtl. vergeben @tharun06 hat das vor 44 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Azure/azure-functions-python-worker#1902 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
Azure/azure-functions-python-worker#1928 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Linux ARM64 packaging omits worker modules and generates protos incompatible with bundled runtimesEvtl. vergeben @hallvictoria hat das vor 7 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Azure/azure-functions-python-worker#1924 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 28/100
Azure/azure-functions-python-worker#1908 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
Azure/azure-functions-python-worker#1906 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in Azure/azure-functions-python-worker
Ähnliche Issues
-
fuzz fuzz-unconfirmed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
ready-for-agent
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
neilsh/stunt-reel#220 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Issue]: use_fp4_cache is accepted but ignored; the launcher always writes FP8 recordsEvtl. vergeben @0z5a hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
area: cli priority: p3 size: S type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
finos/open-resource-broker#757 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 6 Tagen