fix(decay-engine): strip tzinfo from validated_at before datetime arithmetic
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
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:
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user