fix(decay-engine): strip tzinfo from validated_at before datetime arithmetic

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.
This commit is contained in:
kitos
2026-05-19 16:35:02 +02:00
parent 61c26ddd0f
commit b493f92f75
+3 -4
View File
@@ -81,10 +81,9 @@ def calculate_confidence_for_technique(db: Session, technique_id: UUID) -> Optio
last_validated = None last_validated = None
if valid_validations: if valid_validations:
most_recent = max(v.validated_at for v in valid_validations) most_recent = max(v.validated_at for v in valid_validations)
# Make timezone-aware if needed # Strip tzinfo if present so arithmetic stays consistent with naive UTC
if most_recent.tzinfo is None: if most_recent.tzinfo is not None:
from datetime import timezone as _tz most_recent = most_recent.replace(tzinfo=None)
most_recent = most_recent.replace(tzinfo=_tz.utc)
last_validated = most_recent last_validated = most_recent
days_since = (now - most_recent).days days_since = (now - most_recent).days
if days_since <= policy.fresh_days: if days_since <= policy.fresh_days: