fix(db): stabilize connection refreshing and prevent ResourceClosedError
- Update sql_connect to refresh global db object via reconnect_db - Add returns_rows check and safe fetch block in sql_select - Prevents 500 errors during transient database connection issues
This commit is contained in:
@@ -77,10 +77,12 @@ def reconnect_db() -> bool:
|
||||
log.exception("DB SQL Core: FAILED to refresh database connection!")
|
||||
return False
|
||||
|
||||
def sql_connect(current_db, log_lvl: int = logging.INFO) -> bool:
|
||||
"""Old compatibility wrapper for disposing the engine."""
|
||||
if current_db:
|
||||
current_db.engine.dispose()
|
||||
log.info('DB SQL Core: Disposed of the current engine via sql_connect.')
|
||||
return True
|
||||
return False
|
||||
def sql_connect(current_db=None, log_lvl: int = logging.INFO) -> bool:
|
||||
|
||||
"""Refreshes the global database connection."""
|
||||
|
||||
log.setLevel(log_lvl)
|
||||
|
||||
log.info('DB SQL Core: Refreshing database connection via sql_connect...')
|
||||
|
||||
return reconnect_db()
|
||||
Reference in New Issue
Block a user