From 41dd80b69f5f12b783041d5a581b057a8d8ec42b Mon Sep 17 00:00:00 2001 From: maziggy Date: Fri, 27 Feb 2026 17:45:58 +0100 Subject: [PATCH] Fix naive-vs-aware datetime crash from 0.2.1 timezone migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- backend/app/api/routes/maintenance.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/app/api/routes/maintenance.py b/backend/app/api/routes/maintenance.py index 4efae8414..88ea766f4 100644 --- a/backend/app/api/routes/maintenance.py +++ b/backend/app/api/routes/maintenance.py @@ -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