From 572dbf393ee5528cdc02f339306053744df8b1b3 Mon Sep 17 00:00:00 2001 From: maziggy Date: Tue, 3 Feb 2026 07:54:03 +0100 Subject: [PATCH] Fix 500 error on GET /archives/{id} endpoint Load project relationship in ArchiveService.get_archive() alongside created_by. Async SQLAlchemy doesn't support lazy loading, so project must be eagerly loaded for archive_to_response() to access project.name. --- CHANGELOG.md | 4 ++++ backend/app/services/archive.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21581c67e..bc8dd9e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,10 @@ All notable changes to Bambuddy will be documented in this file. - Placeholder text shows expected format (e.g., "DD/MM/YYYY" or "HH:MM AM/PM") - Added date utilities: `formatDateInput`, `parseDateInput`, `getDatePlaceholder` - Added time utilities: `formatTimeInput`, `parseTimeInput`, `getTimePlaceholder` +- **500 Error on Archive Detail Page**: + - Fixed internal server error when viewing individual archive details + - Root cause: `project` relationship not eagerly loaded in `get_archive()` service method + - Async SQLAlchemy requires explicit eager loading; lazy loading is not supported ## [0.1.6.2] - 2026-02-02 diff --git a/backend/app/services/archive.py b/backend/app/services/archive.py index 840be0999..39037e703 100644 --- a/backend/app/services/archive.py +++ b/backend/app/services/archive.py @@ -933,11 +933,13 @@ class ArchiveService: return archive async def get_archive(self, archive_id: int) -> PrintArchive | None: - """Get an archive by ID with creator loaded.""" + """Get an archive by ID with relationships loaded.""" from sqlalchemy.orm import selectinload result = await self.db.execute( - select(PrintArchive).options(selectinload(PrintArchive.created_by)).where(PrintArchive.id == archive_id) + select(PrintArchive) + .options(selectinload(PrintArchive.created_by), selectinload(PrintArchive.project)) + .where(PrintArchive.id == archive_id) ) return result.scalar_one_or_none()