From 76764384660d7311f08730a337ae0fcc2108a078 Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Mon, 11 May 2026 21:40:52 +0200 Subject: [PATCH] fix(tests): resolve lazy loading errors in test_engine.py Add await db.refresh() calls with relationship attributes before accessing test_job.executions and execution.backups in async test context. Fixes lazy loading errors in: - test_execute_full_backup - test_execute_incremental_without_full --- backend/tests/test_engine.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/tests/test_engine.py b/backend/tests/test_engine.py index ecbad4b..12891c3 100644 --- a/backend/tests/test_engine.py +++ b/backend/tests/test_engine.py @@ -4,6 +4,7 @@ import tempfile import os from pathlib import Path from sqlalchemy.ext.asyncio import AsyncSession +from sqlalchemy.orm import selectinload from app.models import Source, Job, JobExecution from backup.engine import BackupEngine @@ -49,8 +50,14 @@ async def test_execute_full_backup(db: AsyncSession, test_job): assert execution.bytes_backed_up > 0 assert execution.triggered_by == "manual" + # Refresh test_job to load executions relationship + await db.refresh(test_job, ["executions"]) + # Verify backup was created assert len(test_job.executions) == 1 + + # Refresh execution to load backups relationship + await db.refresh(test_job.executions[0], ["backups"]) backup = test_job.executions[0].backups[0] assert backup.type == "full" assert backup.checksum is not None @@ -67,6 +74,9 @@ async def test_execute_incremental_without_full(db: AsyncSession, test_job): # Should fall back to full backup assert execution.status == "success" + + # Refresh execution to load backups relationship + await db.refresh(execution, ["backups"]) backup = execution.backups[0] assert backup.type == "full" assert backup.parent_backup_id is None