From 7b0a161d3d8a44410b14129b8d9ee277683741c0 Mon Sep 17 00:00:00 2001 From: ZdenekSrotyr Date: Mon, 30 Mar 2026 14:19:40 +0200 Subject: [PATCH] fix: handle timezone-naive timestamps in health check --- app/api/health.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/api/health.py b/app/api/health.py index 100d66b..e80ba17 100644 --- a/app/api/health.py +++ b/app/api/health.py @@ -33,8 +33,16 @@ async def health_check(conn: duckdb.DuckDBPyConnection = Depends(_get_db)): now = datetime.now(timezone.utc) for s in all_states: last = s.get("last_sync") - if last and (now - last).total_seconds() > 86400: # >24h - stale.append(s["table_id"]) + if last: + try: + # Handle both tz-aware and tz-naive datetimes from DuckDB + if hasattr(last, 'tzinfo') and last.tzinfo is None: + from datetime import timezone as tz + last = last.replace(tzinfo=tz.utc) + if (now - last).total_seconds() > 86400: + stale.append(s["table_id"]) + except (TypeError, AttributeError): + pass # skip if timestamp comparison fails checks["data"] = { "status": "ok" if not stale else "warning", "tables": total_tables,