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) <noreply@anthropic.com>
This commit is contained in:
Adriano Dal Pastro
2026-06-05 07:50:58 +00:00
parent d2bf0b5828
commit a7254d8932
+4 -1
View File
@@ -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()}