-
Notifications
You must be signed in to change notification settings - Fork 8.2k
fix(api): parse multipart/form-data and extract session_id for /run (fixes #9859) #10682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
93766ba
9606701
eb8b685
8dc224a
6dbf2e7
9478d1a
62a7ebe
e2ee874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,38 @@ | |
| SimplifiedAPIRequest: Parsed request or default instance if parsing fails | ||
| """ | ||
| try: | ||
| content_type = (http_request.headers.get("content-type") or "").lower() | ||
|
|
||
| # If multipart/form-data, use request.form() so uploaded files are not consumed | ||
| if "multipart/form-data" in content_type: | ||
| form = await http_request.form() | ||
| data: dict = {} | ||
|
|
||
| # Map expected form fields to the SimplifiedAPIRequest schema | ||
| if "input_value" in form: | ||
| data["input_value"] = form.get("input_value") | ||
| if "input_type" in form: | ||
| data["input_type"] = form.get("input_type") | ||
| if "output_type" in form: | ||
| data["output_type"] = form.get("output_type") | ||
| if "output_component" in form: | ||
| data["output_component"] = form.get("output_component") | ||
| if "session_id" in form: | ||
| data["session_id"] = form.get("session_id") | ||
|
|
||
| # Tweaks may be JSON encoded in a form field | ||
| if "tweaks" in form: | ||
| raw_tweaks = form.get("tweaks") | ||
| if raw_tweaks: | ||
| try: | ||
| data["tweaks"] = orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks | ||
| except Exception: | ||
| # Leave as raw value if parsing fails | ||
| data["tweaks"] = raw_tweaks | ||
|
Comment on lines
99
to
108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve exception handling and add type validation. Two issues:
Apply this diff: # Tweaks may be JSON encoded in a form field
if "tweaks" in form:
raw_tweaks = form.get("tweaks")
- if raw_tweaks:
+ if raw_tweaks and isinstance(raw_tweaks, (str, bytes)):
try:
- data["tweaks"] = (
- orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks
- )
- except Exception:
+ data["tweaks"] = orjson.loads(raw_tweaks)
+ except (ValueError, orjson.JSONDecodeError):
# Leave as raw value if parsing fails
data["tweaks"] = raw_tweaks🧰 Tools🪛 GitHub Actions: Ruff Style Check[error] 100-100: ruff check failed: E501 Line too long (121 > 120) in src/backend/base/langflow/api/v1/endpoints.py. Command: uv run --only-dev ruff check --output-format=github . 🪛 GitHub Check: Ruff Style Check (3.13)[failure] 101-101: Ruff (BLE001) [failure] 100-100: Ruff (E501) |
||
|
|
||
| return SimplifiedAPIRequest(**data) | ||
|
|
||
| # Fallback: parse as JSON (application/json or others) | ||
| body = await http_request.body() | ||
| if body: | ||
| body_data = orjson.loads(body) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix line length to pass pipeline check.
Line 100 exceeds the 120-character limit, causing the Ruff style check to fail.
Apply this diff to split the line:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Ruff Style Check
[error] 100-100: ruff check failed: E501 Line too long (121 > 120) in src/backend/base/langflow/api/v1/endpoints.py. Command: uv run --only-dev ruff check --output-format=github .
🪛 GitHub Check: Ruff Style Check (3.13)
[failure] 100-100: Ruff (E501)
src/backend/base/langflow/api/v1/endpoints.py:100:121: E501 Line too long (121 > 120)
🤖 Prompt for AI Agents