fix(decay-engine): strip tzinfo from validated_at before datetime arithmetic
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled

The previous fix changed _now() to return naive UTC, but the code still
called .replace(tzinfo=utc) on most_recent (from DB) before subtracting.
This caused "can't subtract offset-naive and offset-aware datetimes".
Now we strip tzinfo if present, keeping everything naive UTC consistently.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kitos
2026-05-19 16:35:02 +02:00
parent 9a020f97ef
commit 89a951c2a2

View File

@@ -81,10 +81,9 @@ def calculate_confidence_for_technique(db: Session, technique_id: UUID) -> Optio
last_validated = None
if valid_validations:
most_recent = max(v.validated_at for v in valid_validations)
# Make timezone-aware if needed
if most_recent.tzinfo is None:
from datetime import timezone as _tz
most_recent = most_recent.replace(tzinfo=_tz.utc)
# Strip tzinfo if present so arithmetic stays consistent with naive UTC
if most_recent.tzinfo is not None:
most_recent = most_recent.replace(tzinfo=None)
last_validated = most_recent
days_since = (now - most_recent).days
if days_since <= policy.fresh_days: