fix(monitoring): handle timezone-naive datetimes in get_server_states_view
Fixes datetime comparison error when last_seen_at from database is offset-naive (no timezone info) while 'now' is offset-aware (UTC). This resolves the TypeError: can't subtract offset-naive and offset-aware datetimes issue in integration tests.
This commit is contained in:
@@ -288,6 +288,9 @@ def get_server_states_view(db: Session, offline_after_minutes: int = 7):
|
||||
for s in servers:
|
||||
st = db.query(ServerState).filter(ServerState.server_id == s.id).first()
|
||||
last_seen = st.last_seen_at if st else None
|
||||
# Handle timezone-naive datetimes from database
|
||||
if last_seen and last_seen.tzinfo is None:
|
||||
last_seen = last_seen.replace(tzinfo=timezone.utc)
|
||||
online = bool(last_seen and (now - last_seen).total_seconds() <= offline_after_minutes * 60)
|
||||
out.append({
|
||||
'server_id': s.id,
|
||||
|
||||
Reference in New Issue
Block a user