修复: MissingGreenlet_product访问try/catch + spawn_subtask不再覆盖overall_status

This commit is contained in:
2026-08-06 11:16:07 +08:00
parent 3176bcde6f
commit 9846dd6c8f
2 changed files with 21 additions and 9 deletions

View File

@ -15,11 +15,19 @@ from app.schemas.task import TaskSummaryResponse, TaskResponse, TaskRecordRespon
def _task_to_response(task: Task) -> TaskResponse: def _task_to_response(task: Task) -> TaskResponse:
"""将 Task ORM 对象递归转为 TaskResponse含子任务树""" """将 Task ORM 对象递归转为 TaskResponse含子任务树"""
product_sn = ""
product_material = ""
try:
if task.product:
product_sn = task.product.serial_number or ""
product_material = (task.product.material_name or task.product.material_id or "")
except Exception:
pass
return TaskResponse( return TaskResponse(
id=task.id, id=task.id,
product_id=task.product_id, product_id=task.product_id,
product_sn=task.product.serial_number if task.product else "", product_sn=product_sn,
product_material=task.product.material_name or task.product.material_id or "" if task.product else "", product_material=product_material,
parent_task_id=task.parent_task_id, parent_task_id=task.parent_task_id,
task_name=task.task_name, task_name=task.task_name,
assignee_id=task.assignee_id, assignee_id=task.assignee_id,

View File

@ -93,11 +93,19 @@ async def _get_task_with_children_recursive(db: AsyncSession, task_id: uuid.UUID
def _to_response(task: Task) -> TaskResponse: def _to_response(task: Task) -> TaskResponse:
"""将 Task ORM 对象转为递归 TaskResponse""" """将 Task ORM 对象转为递归 TaskResponse"""
product_sn = ""
product_material = ""
try:
if task.product:
product_sn = task.product.serial_number or ""
product_material = (task.product.material_name or task.product.material_id or "")
except Exception:
pass
return TaskResponse( return TaskResponse(
id=task.id, id=task.id,
product_id=task.product_id, product_id=task.product_id,
product_sn=task.product.serial_number if task.product else "", product_sn=product_sn,
product_material=task.product.material_name or task.product.material_id or "" if task.product else "", product_material=product_material,
parent_task_id=task.parent_task_id, parent_task_id=task.parent_task_id,
task_name=task.task_name, task_name=task.task_name,
assignee_id=task.assignee_id, assignee_id=task.assignee_id,
@ -295,11 +303,7 @@ async def spawn_subtask(
db.add(child) db.add(child)
await db.flush() await db.flush()
# 同步产品宏观状态 # 协助分支不改变产品宏观状态(只有主分支影响 overall_status
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
product = product_result.scalar_one_or_none()
if product and data.task_name:
product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id, await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id}") remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id}")