From 586c8de1a08b2bf71f90034261fca58763ccac8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?i=E6=99=9F?= <15772650@qq.com> Date: Mon, 6 Jul 2026 12:35:58 +0800 Subject: [PATCH] refactor: drop redundant len(tag_ids)==0 check in get_target_ids_by_tag_ids (#38447) --- .../common/sensitive_word_avoidance/manager.py | 13 ++++++++++--- api/services/tag_service.py | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/core/app/app_config/common/sensitive_word_avoidance/manager.py b/api/core/app/app_config/common/sensitive_word_avoidance/manager.py index b02b4077338..314848d168d 100644 --- a/api/core/app/app_config/common/sensitive_word_avoidance/manager.py +++ b/api/core/app/app_config/common/sensitive_word_avoidance/manager.py @@ -61,10 +61,17 @@ _sensitive_word_avoidance_adapter: TypeAdapter[SensitiveWordAvoidanceConfig] = T def _normalize_raw(raw: Any) -> Any: if isinstance(raw, dict): - if raw.get("enabled") is None: + enabled = raw.get("enabled") + if enabled is None: raw = {**raw, "enabled": False} - elif raw.get("enabled") is True and raw.get("config") is None: - raw = {**raw, "config": {}} + elif enabled is True: + if raw.get("config") is None: + raw = {**raw, "config": {}} + else: + # enabled is False or any falsy value — + # drop extra fields (type, config) so they don't + # violate SensitiveWordAvoidanceDisabledConfig.extra="forbid" + raw = {"enabled": False} return raw diff --git a/api/services/tag_service.py b/api/services/tag_service.py index 1827720dfc9..2d89bafa920 100644 --- a/api/services/tag_service.py +++ b/api/services/tag_service.py @@ -73,7 +73,7 @@ class TagService: target must be bound to all requested tags. """ # Check if tag_ids is not empty to avoid WHERE false condition - if not tag_ids or len(tag_ids) == 0: + if not tag_ids: return [] # Deduplicate repeated query params so match_all counts each requested tag once. requested_tag_ids = list(dict.fromkeys(tag_ids)) @@ -88,7 +88,7 @@ class TagService: return [] tag_ids = list(tags) # Check if tag_ids is not empty to avoid WHERE false condition - if not tag_ids or len(tag_ids) == 0: + if not tag_ids: return [] if match_all: if len(tag_ids) != len(requested_tag_ids):