From d737946aac3cb3cd5cdb1fa552dae093214fe5f1 Mon Sep 17 00:00:00 2001 From: Sanaullah Turab Date: Fri, 11 Sep 2026 18:48:56 +0500 Subject: [PATCH] fix(datetime): replace deprecated utcnow() with timezone-aware equivalent (#15) - Replaced datetime.utcnow() with datetime.now(timezone.utc) in router and observability modules - Preserves backwards compatibility with Python 3.10+ - Fixes #14 --- backend/app/observability/events.py | 4 ++-- backend/app/router/engine.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/observability/events.py b/backend/app/observability/events.py index cdf93ad..96a2936 100644 --- a/backend/app/observability/events.py +++ b/backend/app/observability/events.py @@ -1,4 +1,4 @@ -import json +import json import logging from typing import Dict, Any, Optional import datetime @@ -27,7 +27,7 @@ def log_router_event( payload = { "event": event_name, "request_id": request_id, - "timestamp": datetime.datetime.utcnow().isoformat(), + "timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(), "model": model, "provider": provider, "duration_ms": duration_ms, diff --git a/backend/app/router/engine.py b/backend/app/router/engine.py index 21b8519..75fa8d4 100644 --- a/backend/app/router/engine.py +++ b/backend/app/router/engine.py @@ -1,4 +1,4 @@ -import uuid +import uuid import datetime from typing import List, Dict, Any, Optional from app.models.schemas import ( @@ -64,7 +64,7 @@ def route_request( ) -> RoutingDecision: req_id = request_id or str(uuid.uuid4()) decision_id = f"dec_{uuid.uuid4().hex[:12]}" - now_iso = datetime.datetime.utcnow().isoformat() + now_iso = datetime.datetime.now(datetime.timezone.utc).isoformat() # 1. Rule evaluation rule_action, rule_target, rule_name = None, None, None