Просмотр исходного кода

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.
maziggy 3 месяцев назад
Родитель
Сommit
5b76cf3623
2 измененных файлов с 8 добавлено и 2 удалено
  1. 4 0
      CHANGELOG.md
  2. 4 2
      backend/app/services/archive.py

+ 4 - 0
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
 

+ 4 - 2
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()