Fix SyntaxError: move global declarations before variable usage in get_db function
This commit is contained in:
parent
dd38de25ee
commit
b36326d1a5
@ -105,10 +105,11 @@ except Exception as e:
|
|||||||
# Dependency to get DB session
|
# Dependency to get DB session
|
||||||
def get_db():
|
def get_db():
|
||||||
"""FastAPI dependency for database sessions with error handling."""
|
"""FastAPI dependency for database sessions with error handling."""
|
||||||
|
global engine, SessionLocal
|
||||||
|
|
||||||
if not SessionLocal:
|
if not SessionLocal:
|
||||||
logger.error("Database session not initialized, attempting to initialize")
|
logger.error("Database session not initialized, attempting to initialize")
|
||||||
# Last chance to initialize
|
# Last chance to initialize
|
||||||
global engine, SessionLocal
|
|
||||||
try:
|
try:
|
||||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user