From a7254d89324422492e1f5c97e1ab67793703f375 Mon Sep 17 00:00:00 2001 From: Adriano Dal Pastro Date: Fri, 5 Jun 2026 07:50:58 +0000 Subject: [PATCH] fix(tasks): eager-load version in reorder endpoint to fix MissingGreenlet The reorder_tasks endpoint loaded RecipeTask with selectinload(subtasks) only. Serializing via TaskResponse reads RecipeTask.recipe_id, a @property that traverses the version relationship, triggering a lazy load outside the async greenlet context -> MissingGreenlet error. Add selectinload(RecipeTask.version), matching the pattern already used in the get-task flow. Fixes the previously order-dependent test_reorder_tasks failure; full suite now 179 passed. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/backend/api/routers/tasks.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/api/routers/tasks.py b/src/backend/api/routers/tasks.py index b682fb7..501dbba 100644 --- a/src/backend/api/routers/tasks.py +++ b/src/backend/api/routers/tasks.py @@ -223,7 +223,10 @@ async def reorder_tasks( result = await db.execute( select(RecipeTask) .where(RecipeTask.id.in_(data.task_ids)) - .options(selectinload(RecipeTask.subtasks)) + .options( + selectinload(RecipeTask.subtasks), + selectinload(RecipeTask.version), + ) ) tasks_map = {t.id: t for t in result.scalars().all()}