From 118260a7101cee22014dcc93bf33efbc2f4072fe Mon Sep 17 00:00:00 2001 From: XingQue Date: Thu, 16 Jul 2026 15:33:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=80=83=E6=A0=B8?= =?UTF-8?q?=E5=AE=98=E6=B7=BB=E5=8A=A0=E6=9D=BF=E5=9D=97=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E4=B8=8E=E6=9D=BF=E5=9D=97=E6=94=B9=E5=90=8D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 板块 ID 统一按整数校验,避免字符串与数据库整型比较导致误报不存在;板块接口补充 scope 与 bankuai_id 校验。 Co-authored-by: Cursor --- backend/views/sections.py | 12 ++++++++---- jituan/views_shenhe_manage.py | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/views/sections.py b/backend/views/sections.py index d99a9e5..6e99d73 100644 --- a/backend/views/sections.py +++ b/backend/views/sections.py @@ -139,7 +139,7 @@ class HqbkxxView(APIView): return Response({'code': 403, 'msg': '无板块管理权限'}, status=403) scope_err = block_non_group_catalog_scope(request) if scope_err: - return Response({'code': 400, 'msg': scope_err}) + return Response({'code': 400, 'msg': scope_err}, status=400) # 5. 查询所有板块 bankuai_list = [] @@ -241,7 +241,7 @@ class BkxgView(APIView): return Response({'code': 403, 'msg': '无板块管理权限'}, status=403) scope_err = block_non_group_catalog_scope(request) if scope_err: - return Response({'code': 400, 'msg': scope_err}) + return Response({'code': 400, 'msg': scope_err}, status=400) # 5. 获取操作类型 action = request.data.get('action') @@ -279,9 +279,13 @@ class BkxgView(APIView): }) # ==================== 以下操作需要 bankuai_id ==================== - bankuai_id = request.data.get('bankuai_id') - if not bankuai_id: + raw_bankuai_id = request.data.get('bankuai_id') + if raw_bankuai_id is None or str(raw_bankuai_id).strip() == '': return Response({'code': 1, 'msg': '缺少 bankuai_id'}, status=400) + try: + bankuai_id = int(raw_bankuai_id) + except (TypeError, ValueError): + return Response({'code': 1, 'msg': '无效的 bankuai_id'}, status=400) try: bk = Bankuai.query.get(bankuai_id=bankuai_id) diff --git a/jituan/views_shenhe_manage.py b/jituan/views_shenhe_manage.py index f2da2b9..a5e748b 100644 --- a/jituan/views_shenhe_manage.py +++ b/jituan/views_shenhe_manage.py @@ -17,16 +17,20 @@ logger = logging.getLogger(__name__) def _normalize_bankuai_ids(data): + """将板块 ID 统一为整数(bankuai_id 为 AutoField)。""" ids = data.get('bankuai_ids') - if ids is None and data.get('bankuai_id'): + if ids is None and data.get('bankuai_id') is not None: ids = [data.get('bankuai_id')] if not isinstance(ids, list): return [] out = [] for item in ids: - s = str(item or '').strip() - if s and s not in out: - out.append(s) + try: + bid = int(str(item).strip()) + except (TypeError, ValueError): + continue + if bid > 0 and bid not in out: + out.append(bid) return out