Skip to content

fix(api): reject conflicting multipart file shapes - #44903

Merged
crazywoola merged 3 commits into
langgenius:mainfrom
Winoren:fix/openapi-multipart-shape-conflicts
Oct 30, 2026
Merged

crazywoola merged 3 commits into
langgenius:mainfrom
Winoren:fix/openapi-multipart-shape-conflicts

Conversation

@Winoren

@Winoren Winoren commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #44902.

OpenAPI multipart requests that mix files (or files[]) with files[doc] (or files[doc][]) currently return an unhandled HTTP 500 when the direct part comes first. Reversing the same parts already returns the intended HTTP 422 invalid_param.

Check that the existing target is a mapping before looking up or assigning a keyed part. Incompatible file/list/map shapes now use the existing InvalidFilePart error consistently in either order. Valid multipart shapes and the public error schema are unchanged.

Added eight regression cases covering scalar/list and keyed scalar/list parts in both orders.

The repository’s autofix bot also corrected one stale Pillow requires-dist constraint in api/uv.lock to match the existing dify-agent/pyproject.toml. This is lock metadata only; no locked package version changed. The unchanged default-branch lock fails uv 0.13.6 lock --check as well, which blocked the first CI run before tests executed.

Validation

  • Unmodified production parser: four new cases fail with TypeError; the other eleven tests pass.
  • After the fix: 117 tests passed across multipart parsing, file adaptation/upload, OpenAPI error formatting, and app execution controller suites.
  • Real Flask test-client multipart requests through the production parser and ExternalApi error formatter: four HTTP 500 responses before the fix; all eight combinations return HTTP 422 invalid_param after the fix. This exercises the HTTP parsing/error boundary; it is not a full deployed workflow run.
  • make lint: passed, including 75 import contracts.
  • make type-check PATH_TO_CHECK=api/controllers/openapi/_multipart.py: passed.
  • Strict unit-test Pyrefly check for test__multipart.py: zero diagnostics.
  • git diff --check: passed.
  • uv 0.13.6 lock --project api --check: passed after the bot’s metadata correction; reproduced the stale-lock failure before that correction.

Checklist

  • This change requires a documentation update, included: Dify Document (not required)
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. (no public contract changes)
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods. (backend lint and scoped production/test type checks; no frontend changes)

AI assistance was used for investigation, implementation, and verification. The results above are local validation; remote CI and maintainer review are separate.

From Codex

@Winoren
Winoren requested a review from QuantumGhost as a code owner October 27, 2026 16:12
@github-actions github-actions Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 81.40% 81.40% +0.00%
Strict coverage 81.10% 81.10% +0.00%
Typed symbols 83,169 83,174 +5
Untyped symbols 19,079 19,079 0
Modules 4240 4240 0

@autofix-ci
autofix-ci Bot requested a review from a team October 27, 2026 16:16
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.67%. Comparing base (9e20db9) to head (2c2a6dc).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #44903       +/-   ##
===========================================
+ Coverage   68.68%   89.67%   +20.98%     
===========================================
  Files        6083     6149       +66     
  Lines      367753   390568    +22815     
  Branches    77976    77656      -320     
===========================================
+ Hits       252597   350239    +97642     
+ Misses     112353    34028    -78325     
- Partials     2803     6301     +3498     
Flag Coverage Δ
api 89.63% <100.00%> (+37.77%) ⬆️

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.

@crazywoola
crazywoola added this pull request to the merge queue Oct 30, 2026
Merged via the queue into langgenius:main with commit 2c3cbd5 Oct 30, 2026
47 checks passed
@laipz8200 laipz8200 mentioned this pull request Nov 3, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI mixed file-part shapes return HTTP 500 depending on part order

2 participants