From 059c436717dd48776a68deb49d736ba3cfdf2c28 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Wed, 18 Feb 2026 20:58:11 +0100 Subject: [PATCH] code-review-fix task 15.3: replace datetime.utcnow() with datetime.now(timezone.utc) in main.py --- services/ml/app/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/ml/app/main.py b/services/ml/app/main.py index 83fc328..3632072 100644 --- a/services/ml/app/main.py +++ b/services/ml/app/main.py @@ -14,7 +14,7 @@ import uuid from contextlib import asynccontextmanager from pathlib import Path from typing import Optional, Dict, Any, List -from datetime import datetime +from datetime import datetime, timezone import json import requests as http_requests @@ -81,7 +81,7 @@ async def lifespan(app: FastAPI): .where(TrainingRun.status == "running") .values( status="failed", - completed_at=datetime.utcnow(), + completed_at=datetime.now(timezone.utc), metrics_summary={"error": "Service restarted while training was in progress"}, ) ) @@ -1226,7 +1226,7 @@ def _run_training_background(run_id: str, model_type: str, config: PipelineConfi .where(TrainingRun.run_id == run_id) .values( status="failed", - completed_at=datetime.utcnow(), + completed_at=datetime.now(timezone.utc), metrics_summary={ "error": "Training timed out after 30 minutes" }, @@ -1268,7 +1268,7 @@ def _run_training_background(run_id: str, model_type: str, config: PipelineConfi "model": model_instance, "metadata": { "model_type": model_type, - "trained_at": datetime.utcnow().isoformat(), + "trained_at": datetime.now(timezone.utc).isoformat(), "run_id": run_id, "feature_columns": feature_cols, "labels": ( @@ -1288,7 +1288,7 @@ def _run_training_background(run_id: str, model_type: str, config: PipelineConfi .where(TrainingRun.run_id == run_id) .values( status="completed", - completed_at=datetime.utcnow(), + completed_at=datetime.now(timezone.utc), metrics_summary=metrics, ) ) @@ -1306,7 +1306,7 @@ def _run_training_background(run_id: str, model_type: str, config: PipelineConfi .where(TrainingRun.run_id == run_id) .values( status="failed", - completed_at=datetime.utcnow(), + completed_at=datetime.now(timezone.utc), metrics_summary={"error": str(exc)}, ) ) @@ -1368,7 +1368,7 @@ async def training_start(request: TrainingStartRequest): experiment_name=config.stages.training.mlflow.experiment_name, pipeline_config_hash=config_hash, status="running", - created_at=datetime.utcnow(), + created_at=datetime.now(timezone.utc), metrics_summary={}, ) db.add(training_run)