Fix SyntaxError: move global declarations before variable usage in get_db function

This commit is contained in:
Automated Action 2025-06-03 10:43:26 +00:00
parent dd38de25ee
commit b36326d1a5

View File

@ -105,10 +105,11 @@ except Exception as e:
# Dependency to get DB session
def get_db():
"""FastAPI dependency for database sessions with error handling."""
global engine, SessionLocal
if not SessionLocal:
logger.error("Database session not initialized, attempting to initialize")
# Last chance to initialize
global engine, SessionLocal
try:
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)