Skip to content

refactor: drop redundant len(tag_ids)==0 check in get_target_ids_by_tag_ids#38447

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
isheng-eqi:refactor/drop-redundant-len-check
Jul 6, 2026
Merged

refactor: drop redundant len(tag_ids)==0 check in get_target_ids_by_tag_ids#38447
asukaminato0721 merged 2 commits into
langgenius:mainfrom
isheng-eqi:refactor/drop-redundant-len-check

Conversation

@isheng-eqi

Copy link
Copy Markdown
Contributor

Summary

Fixes #38405

Problem

Both branches of get_target_ids_by_tag_ids() in api/services/tag_service.py use:

if not tag_ids or len(tag_ids) == 0:

The len(tag_ids) == 0 disjunct is fully redundant — any sequence where len(x) == 0 also satisfies not x. This is a holdover from the recent TagService refactor (#38313) which switched the signature to an explicit session argument but didn't collapse the guard.

Fix

Collapse both guards to if not tag_ids:.

Changes

  • api/services/tag_service.py: Remove or len(tag_ids) == 0 from lines 76 and 91

No behavior change. No public API change.

When a client sends sensitive_word_avoidance with enabled=false but
also includes type/config fields, _normalize_raw() passes them through
unchanged. This causes pydantic ValidationError because
SensitiveWordAvoidanceDisabledConfig has extra='forbid', resulting in
HTTP 400 invalid_param.

Add an else branch to strip extra fields when enabled is not True,
keeping only {'enabled': False}.

Fixes langgenius#38409
…ag_ids

Both branches of get_target_ids_by_tag_ids() use:
  if not tag_ids or len(tag_ids) == 0:

The second disjunct is subsumed by 'not tag_ids' — any sequence
where len(x)==0 also satisfies 'not x'. Collapse to just
'if not tag_ids:' for clarity. No behavior change.

Fixes langgenius#38405
@isheng-eqi isheng-eqi requested a review from QuantumGhost as a code owner July 6, 2026 03:48
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.38% 52.38% 0.00%
Strict coverage 51.89% 51.89% 0.00%
Typed symbols 32,079 32,079 0
Untyped symbols 29,438 29,438 0
Modules 2973 2973 0

@asukaminato0721 asukaminato0721 enabled auto-merge July 6, 2026 04:35
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Jul 6, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2026
Merged via the queue into langgenius:main with commit 586c8de Jul 6, 2026
31 checks passed
@isheng-eqi

Copy link
Copy Markdown
Contributor Author

感谢 @asukaminato0721 快速 review 和合入!

简单介绍一下自己——我是太原理工大学(211)软件工程大二学生,专注 AI Agent 开发。之前做过几个相关项目:

  • Claude Code 全链路逆向(拆解 Agent Loop、System Prompt 构造、60+ Tool Use 调度),编译了自己的定制版
  • skill-builder-v3:自进化 Agent 技能引擎,MCP 协议集成,闭合修复循环
  • pure-chat:对接 14 家 LLM API,系统对比各模型在零包装下的行为差异

提交的 6 个 PR 让我对 Dify 的代码库越来越熟悉,尤其是 Agent 和 RAG 相关模块。想问问团队是否招实习生?我暑期可立即到岗。邮箱 ishengeqi@163.com,GitHub: isheng-eqi。期待有机会更深入参与!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: drop redundant len(tag_ids) == 0 check in get_target_ids_by_tag_ids

2 participants