Skip to content

fix(api): parse Python repr strings for multiple-select tool parameters - #45676

Open
sx4im wants to merge 3 commits into
langgenius:mainfrom
sx4im:fix-45672-multiple-select-repr
Open

sx4im wants to merge 3 commits into
langgenius:mainfrom
sx4im:fix-45672-multiple-select-repr

Conversation

@sx4im

@sx4im sx4im commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #45672

A tool node constant like ["id1", "id2"] gets stringified to "['id1', 'id2']" by the workflow engine before it reaches tool validation. The comma-split in init_frontend_parameter then turned it into ["['id1'", "'id2']"], so the tool received corrupted ids, and static selects failed the options check instead.

This parses a bracketed string back to a list first, and falls back to the existing comma-split for anything else. A list constant now reaches the tool unchanged.

The same stringification also happens upstream in graphon; this fixes it where dify validates the value, so existing workflows work without waiting on a graphon release and pin bump.

Verified: new regression tests in test_tool_entities.py fail before the fix and pass after. Ran the tool entities, agent plugin entities, and datasource entities suites (97 passed), plus the neighboring tool suites. Ruff check and format clean, pyrefly clean on the changed file.

The workflow engine stringifies a list constant to its Python repr
("['id1', 'id2']") before it reaches tool validation, and the
comma-split normalization turned it into ["['id1'", "'id2']"], so the
tool received corrupted ids (and static selects failed the options
check). Parse a bracketed string back to a list with ast.literal_eval
first and fall back to comma-splitting otherwise.

Fixes langgenius#45672
@sx4im
sx4im requested a review from QuantumGhost as a code owner November 5, 2026 13:20
@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 83.55% 83.55% -0.00%
Strict coverage 83.21% 83.21% -0.00%
Typed symbols 87,084 87,085 +1
Untyped symbols 17,215 17,216 +1
Modules 4415 4415 0

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.97%. Comparing base (5253ee2) to head (5be35a4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
api/core/tools/entities/tool_entities.py 75.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #45676   +/-   ##
=======================================
  Coverage   89.97%   89.97%           
=======================================
  Files        6256     6256           
  Lines      391627   391642   +15     
  Branches    78460    78464    +4     
=======================================
+ Hits       352356   352378   +22     
+ Misses      33181    33174    -7     
  Partials     6090     6090           
Flag Coverage Δ
api 89.76% <75.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sx4im added 2 commits November 5, 2026 18:45
The patch coverage check flagged the two fallback paths in
_parse_multiple_select_string: an unparsable bracketed string and a
bracketed string that parses to something other than a list of strings.
Both fall back to comma splitting; add regression tests pinning that
behavior so the fallback stays covered.

This branch has not been deployed

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool node multiple-select constants are stringified to Python repr and fail validation

1 participant