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:
Scott Idem
2026-01-21 12:49:47 -05:00
parent b2ee1f2760
commit 89bf87cb62
2 changed files with 21 additions and 8 deletions

View File

@@ -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()