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.
This commit is contained in:
maziggy
2026-02-03 09:13:00 +01:00
parent 49daba0579
commit 572dbf393e
2 changed files with 8 additions and 2 deletions
+4
View File
@@ -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
+4 -2
View File
@@ -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()