From 1b934a20374be0c7a1459cbd0bd8cc51e98c6ea8 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Wed, 29 Jul 2026 16:36:34 +0800 Subject: [PATCH] fix(outbound-release): use eq_unicode for schedule id EXISTS joins Avoid Illegal mix of collations when correlating QC/production work orders to infusion schedules in list filters. Co-authored-by: Cursor --- backend/app/crud/outbound_release_review.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/app/crud/outbound_release_review.py b/backend/app/crud/outbound_release_review.py index 33db171d..c5777c36 100644 --- a/backend/app/crud/outbound_release_review.py +++ b/backend/app/crud/outbound_release_review.py @@ -9,6 +9,7 @@ from typing import Any, Dict, List, Optional from sqlalchemy import and_, exists, func, or_ from sqlalchemy.orm import Session +from app.core.db_collation import eq_unicode from app.core.utils import generate_uuid from app.models.models import ( BizOutboundReleaseReview, @@ -105,7 +106,10 @@ def _outbound_qc_unfinished_exists_for_schedule(tenant_no: str): BizQcWorkOrder.del_flag == 0, BizQcWorkOrder.qc_biz_type == "outbound", BizQcWorkOrder.trigger_source == "schedule", - BizQcWorkOrder.infusion_schedule_id == BizPilotInfusionSchedule.id, + # 跨表 id 排序规则可能不同(general_ci vs unicode_ci) + eq_unicode( + BizQcWorkOrder.infusion_schedule_id, BizPilotInfusionSchedule.id + ), BizQcWorkOrder.work_order_status.in_(("dpz", "ypz")), ) ) @@ -121,8 +125,10 @@ def _outbound_production_unfinished_exists_for_schedule(tenant_no: str): BizProductionWorkOrder.tenant_no == tenant_no, BizProductionWorkOrder.del_flag == 0, BizProductionWorkOrder.work_order_type == "outbound", - BizProductionWorkOrder.infusion_schedule_id - == BizPilotInfusionSchedule.id, + eq_unicode( + BizProductionWorkOrder.infusion_schedule_id, + BizPilotInfusionSchedule.id, + ), BizProductionWorkOrder.work_order_status.in_(("dpz", "jxz")), ) ) @@ -136,7 +142,7 @@ def _outbound_qc_all_void_for_schedule(tenant_no: str): BizQcWorkOrder.del_flag == 0, BizQcWorkOrder.qc_biz_type == "outbound", BizQcWorkOrder.trigger_source == "schedule", - BizQcWorkOrder.infusion_schedule_id == BizPilotInfusionSchedule.id, + eq_unicode(BizQcWorkOrder.infusion_schedule_id, BizPilotInfusionSchedule.id), ] any_wo = exists().where(and_(*base)).correlate(BizPilotInfusionSchedule) any_non_void = ( @@ -160,7 +166,9 @@ def _outbound_production_all_void_for_schedule(tenant_no: str): BizProductionWorkOrder.tenant_no == tenant_no, BizProductionWorkOrder.del_flag == 0, BizProductionWorkOrder.work_order_type == "outbound", - BizProductionWorkOrder.infusion_schedule_id == BizPilotInfusionSchedule.id, + eq_unicode( + BizProductionWorkOrder.infusion_schedule_id, BizPilotInfusionSchedule.id + ), ] any_wo = exists().where(and_(*base)).correlate(BizPilotInfusionSchedule) any_non_void = (