mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 09:45:24 -04:00
Replace cleanup service datetime.utcnow calls (#1494)
datetime.utcnow() is deprecated in Python 3.12 and removed in 3.14. Swap the five calls in src/cleanup_service.py for a local _utcnow() helper returning naive UTC, matching the naive DateTime columns the archive/delete cutoffs compare against (same approach as the task-scheduler and core-database slices). Add a regression test asserting the helper stays naive so the cutoff math can't hit a naive/aware TypeError. Part of #1116
This commit is contained in:
committed by
GitHub
parent
6fd52cf317
commit
4f03f5ccdd
@@ -0,0 +1,25 @@
|
||||
"""Regression tests for the datetime.utcnow() removal in src/cleanup_service.py (#1116).
|
||||
|
||||
Importing src.cleanup_service is cheap and dependency-free: its only module-level
|
||||
imports are logging/datetime/typing, and the `from src.database import ...` calls are
|
||||
lazy (inside the functions), so no DB/sqlalchemy stack is pulled in here.
|
||||
"""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from src.cleanup_service import _utcnow
|
||||
|
||||
|
||||
def test_utcnow_returns_naive_utc():
|
||||
now = _utcnow()
|
||||
# Must be naive to match the naive DateTime columns this module compares against.
|
||||
assert now.tzinfo is None
|
||||
ref = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
assert abs((ref - now).total_seconds()) < 5
|
||||
|
||||
|
||||
def test_cutoff_math_stays_naive_and_comparable():
|
||||
# Guards the archive/delete cutoffs against a naive/aware TypeError regression:
|
||||
# an aware _utcnow() would raise when compared with the naive last_accessed column.
|
||||
cutoff = _utcnow() - timedelta(days=7)
|
||||
assert cutoff.tzinfo is None
|
||||
assert cutoff < _utcnow()
|
||||
Reference in New Issue
Block a user