fix: move dispose_engine import inside lifespan function
CI / lint (pull_request) Failing after 2s
CI / test (pull_request) Failing after 15s
CI / build-and-push (pull_request) Has been skipped
CI / deploy-dev (pull_request) Has been skipped
CI / deploy-uat (pull_request) Has been skipped
CI / typecheck (pull_request) Failing after 20s

The top-level import of dispose_engine from cartsnitch_api.database
caused ImportError at module scope because dispose_engine was not
available when main.py was loaded. The function is only used inside
the lifespan context manager, so move the import there.

Fixes: ImportError cannot import name 'dispose_engine' from 'cartsnitch_api.database'

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Barcode Betty
2026-05-23 21:28:41 +00:00
parent 1805ff93cf
commit c005c68230
+1 -1
View File
@@ -6,7 +6,6 @@ from fastapi import APIRouter, FastAPI
from cartsnitch_api.auth.routes import router as auth_router
from cartsnitch_api.cache import cache_client
from cartsnitch_api.database import dispose_engine
from cartsnitch_api.middleware.cors import add_cors_middleware
from cartsnitch_api.middleware.error_handler import add_error_handlers, add_error_monitor_middleware
from cartsnitch_api.middleware.rate_limit import add_rate_limit_middleware
@@ -26,6 +25,7 @@ from cartsnitch_api.routes.user import router as user_router
@asynccontextmanager
async def lifespan(app: FastAPI):
from cartsnitch_api.database import dispose_engine
await cache_client.initialize()
yield
await cache_client.close()