Browse Source

Fix timezone comparison in GitHub backup scheduler

The scheduler compared timezone-aware datetime.now(UTC) with naive
datetimes from the SQLite database, causing "can't compare offset-naive
and offset-aware datetimes" error.

Fixed by adding UTC timezone to naive datetimes before comparison.
maziggy 4 months ago
parent
commit
14e8e512f2
1 changed files with 5 additions and 1 deletions
  1. 5 1
      backend/app/services/github_backup.py

+ 5 - 1
backend/app/services/github_backup.py

@@ -87,7 +87,11 @@ class GitHubBackupService:
 
             now = datetime.now(UTC)
             for config in configs:
-                if config.next_scheduled_run and config.next_scheduled_run <= now:
+                # Handle both naive (from DB) and aware datetimes
+                next_run = config.next_scheduled_run
+                if next_run and next_run.tzinfo is None:
+                    next_run = next_run.replace(tzinfo=UTC)
+                if next_run and next_run <= now:
                     logger.info(f"Running scheduled backup for config {config.id}")
                     await self.run_backup(config.id, trigger="scheduled")