From 589c88ffa2a9b6491f3b00ff071b140e66c5c1bb Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Thu, 21 Nov 2024 13:59:27 +0100 Subject: [PATCH 1/2] Replaced deprecated app on event with app lifespan --- CHANGELOG.md | 1 + preClinVar/main.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 980a9b7..9e2e796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Removed the example of an old json submission (before 2022-11-21) - Updated actions using the latest base images and to run using Python 3.9 - Docker image uses Python 3.11 instead of 3.8 +- Replaced deprecated app "on event" with app lifespan ### Fixed - Updated issue templates - Updated a number of libraries to address all current security advisories diff --git a/preClinVar/main.py b/preClinVar/main.py index da7421c..89f209d 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -1,6 +1,7 @@ import json import logging import re +from contextlib import asynccontextmanager from typing import List import requests @@ -16,16 +17,18 @@ LOG = logging.getLogger("uvicorn.access") -app = FastAPI() - -@app.on_event("startup") -async def startup_event(): +@asynccontextmanager +async def lifespan(app_: FastAPI): LOG = logging.getLogger("uvicorn.access") console_formatter = uvicorn.logging.ColourizedFormatter( "{levelprefix} {asctime} : {message}", style="{", use_colors=True ) LOG.handlers[0].setFormatter(console_formatter) + yield # This is crucial for the lifespan context manager + + +app = FastAPI(lifespan=lifespan) @app.get("/") From 3d1a7b631f81784456bf534bb383873799d534d4 Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Thu, 21 Nov 2024 14:01:00 +0100 Subject: [PATCH 2/2] Remove comment --- preClinVar/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preClinVar/main.py b/preClinVar/main.py index 89f209d..beb0e88 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -25,7 +25,7 @@ async def lifespan(app_: FastAPI): "{levelprefix} {asctime} : {message}", style="{", use_colors=True ) LOG.handlers[0].setFormatter(console_formatter) - yield # This is crucial for the lifespan context manager + yield app = FastAPI(lifespan=lifespan)