From 670209026452ea40c67fd43457e61e68d9acacf6 Mon Sep 17 00:00:00 2001 From: baobao Date: Fri, 30 Oct 2026 10:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=A4=E5=8D=95=E7=8A=B6=E6=80=81=E6=9A=82?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=AF=BB=E6=97=B6=E4=BB=8D=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E7=88=B6=E4=BB=BB=E5=8A=A1=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/dispatcher.py | 11 +++++++++-- scripts/run_tests.py | 2 +- scripts/test_batch52_units.py | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/services/dispatcher.py b/app/services/dispatcher.py index 48f9382..57054b3 100644 --- a/app/services/dispatcher.py +++ b/app/services/dispatcher.py @@ -267,11 +267,18 @@ def cancel(*, instruction_id: str, dispatch_ref=None) -> dict: try: cancel_id = wsc.new_cancel_id(int(datetime.now().strftime("%Y%m%d"))) n = qmt_repo.request_cancel(parent_id=instruction_id, cancel_id=cancel_id) - pending = any(o.get('status') in qmt_repo.LIVE - for o in qmt_repo.orders_for_parent(instruction_id)) except Exception as e: logger.exception("撤单请求落表失败 %s", instruction_id) return {"ok": False, "mode": m, "error": f"{type(e).__name__}: {e}"} + pending = bool(n) + if not pending: + try: + pending = any(o.get('status') in qmt_repo.LIVE + for o in qmt_repo.orders_for_parent(instruction_id)) + except Exception: + # 撤销意图已写入。展示核验失败不能使父任务继续新增或恢复续单。 + pending = True + logger.warning('撤单请求已登记,子委托状态暂不可核实 %s', instruction_id) if not n: return {"ok": True, "mode": m, "cancelled": 0, "cancel_pending": pending, "note": "撤单已在处理中,等待QMT终态" if pending else "该指令名下没有在途子单, 仅本地置撤销"} diff --git a/scripts/run_tests.py b/scripts/run_tests.py index a9f4a2c..d83176c 100644 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -5,7 +5,7 @@ 运行: docker compose run --rm pms-web python scripts/run_tests.py 包含 (例数按 2026-10-26 隔离回归实跑校正): - test_batch52_units.py 当日限价、撤单拒绝、迟到成交、发送恢复与真实SQL状态保护 (21例) + test_batch52_units.py 当日限价、撤单拒绝、迟到成交、发送恢复与真实SQL状态保护 (22例) test_batch51_units.py 跨日决策复核、撤单回报、数量约束、人工确认与真实SQL事务及完整选股接线 (36例) test_batch50_units.py QMT限价等待、价格来源故障、用户暂停、配额防重和试算隔离 (14例) test_batch49_units.py 持仓分组、同名股票与批次归属、未迁移及缺数展示 (8例) diff --git a/scripts/test_batch52_units.py b/scripts/test_batch52_units.py index 56f7fa0..6b96562 100644 --- a/scripts/test_batch52_units.py +++ b/scripts/test_batch52_units.py @@ -154,6 +154,13 @@ class DeadlineTest(unittest.TestCase): result = dispatcher.cancel(instruction_id='P') self.assertTrue(result['ok']); self.assertTrue(result['cancel_pending']) + def test_cancel_intent_survives_status_read_failure(self): + with patch.object(dispatcher, 'mode', return_value='ws'), \ + patch.object(qmt_repo, 'request_cancel', return_value=0), \ + patch.object(qmt_repo, 'orders_for_parent', side_effect=RuntimeError('temporarily unavailable')): + result = dispatcher.cancel(instruction_id='P') + self.assertTrue(result['ok']); self.assertTrue(result['cancel_pending']) + class SqlTest(unittest.TestCase): def setUp(self):