Fix naive-vs-aware datetime crash from 0.2.1 timezone migration

The timezone fix (ed36eaf) replaced datetime.utcnow() with
datetime.now(timezone.utc) across ~80 call sites, but SQLAlchemy's
SQLite DateTime columns strip tzinfo on read, returning naive datetimes.
Any Python-side comparison (subtraction, <, >) between an aware "now"
and a naive DB value raises TypeError.

Add `if value.tzinfo is None: value = value.replace(tzinfo=timezone.utc)`
guards at all 9 affected comparison sites:
- maintenance.py: last_performed_at subtraction (2 code paths — days-based
  and hours-based intervals both crashed on /maintenance/overview)
- auth.py: API key expires_at check (2 locations)
- print_scheduler.py: scheduled_time comparison
- smart_plug_manager.py: auto_off_pending_since elapsed calc
- smart_plugs.py: power_alert_last_triggered cooldown
- main.py: last_runtime_update elapsed calc
- archives.py: timelapse completed_at fallback
This commit is contained in:
maziggy
2026-02-27 17:46:52 +01:00
parent fe5bb1fd90
commit 41dd80b69f
+2
View File
@@ -373,6 +373,8 @@ async def _get_printer_maintenance_internal(
# Calculate days for reference
if last_performed_at:
if last_performed_at.tzinfo is None:
last_performed_at = last_performed_at.replace(tzinfo=timezone.utc)
days_since = (now - last_performed_at).total_seconds() / 86400.0
else:
days_since = None