-
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?
fix(api): parse multipart/form-data and extract session_id for /run (fixes #9859) #10682
Conversation
…to support session_id (fix langflow-ai#9859)
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdded multipart/form-data handling to the API request parsing function. The endpoint now detects multipart requests and extracts form fields (input_value, input_type, output_type, output_component, session_id) plus optional JSON-encoded tweaks, while maintaining backward compatibility with JSON body parsing. Changes
Sequence DiagramsequenceDiagram
participant Client
participant API
participant Endpoint
Client->>API: POST request<br/>(multipart or JSON)
API->>Endpoint: Route to parse_input_request_from_body()
alt Multipart Content-Type
Endpoint->>Endpoint: Read request.form()
Endpoint->>Endpoint: Extract form fields<br/>(input_value, session_id, etc.)
Endpoint->>Endpoint: Parse tweaks field<br/>(JSON decode)
Endpoint->>Endpoint: Construct SimplifiedAPIRequest
else JSON Content-Type
Endpoint->>Endpoint: Parse request body<br/>as JSON (fallback)
Endpoint->>Endpoint: Construct SimplifiedAPIRequest
end
Endpoint->>API: Return SimplifiedAPIRequest
API->>Client: Process request
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touchesImportant Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning, 1 inconclusive)
✅ Passed checks (6 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/backend/base/langflow/api/v1/endpoints.py (1)
84-93: Consider adding type guards for form field extraction.Form fields can be either strings or
UploadFileobjects in multipart requests. If a client mistakenly uploads files under field names likeinput_valueorsession_id, they would beUploadFileobjects, potentially causing Pydantic validation errors when constructingSimplifiedAPIRequest.Apply this diff to add type validation:
# Map expected form fields to the SimplifiedAPIRequest schema if "input_value" in form: - data["input_value"] = form.get("input_value") + val = form.get("input_value") + if isinstance(val, str): + data["input_value"] = val if "input_type" in form: - data["input_type"] = form.get("input_type") + val = form.get("input_type") + if isinstance(val, str): + data["input_type"] = val if "output_type" in form: - data["output_type"] = form.get("output_type") + val = form.get("output_type") + if isinstance(val, str): + data["output_type"] = val if "output_component" in form: - data["output_component"] = form.get("output_component") + val = form.get("output_component") + if isinstance(val, str): + data["output_component"] = val if "session_id" in form: - data["session_id"] = form.get("session_id") + val = form.get("session_id") + if isinstance(val, str): + data["session_id"] = val
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/backend/base/langflow/api/v1/endpoints.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/backend/base/langflow/api/v1/endpoints.py (1)
src/backend/base/langflow/api/v1/schemas.py (1)
SimplifiedAPIRequest(338-347)
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/api/v1/endpoints.py
[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)
src/backend/base/langflow/api/v1/endpoints.py
[failure] 101-101: Ruff (BLE001)
src/backend/base/langflow/api/v1/endpoints.py:101:28: BLE001 Do not catch blind exception: Exception
[failure] 100-100: Ruff (E501)
src/backend/base/langflow/api/v1/endpoints.py:100:121: E501 Line too long (121 > 120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 8/9
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 4/9
- GitHub Check: Lint Backend / Run Mypy (3.10)
- GitHub Check: Lint Backend / Run Mypy (3.12)
- GitHub Check: Lint Backend / Run Mypy (3.11)
- GitHub Check: Test Docker Images / Test docker images
- GitHub Check: Lint Backend / Run Mypy (3.13)
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
- GitHub Check: Run Backend Tests / LFX Tests - Python 3.10
- GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
- GitHub Check: Test Starter Templates
- GitHub Check: Optimize new Python code in this PR
- GitHub Check: Update Component Index
- GitHub Check: Update Starter Projects
🔇 Additional comments (1)
src/backend/base/langflow/api/v1/endpoints.py (1)
76-77: LGTM! Clean content-type detection.The header extraction safely handles missing content-type headers and normalizes to lowercase for reliable matching.
| 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 |
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.
Improve exception handling and add type validation.
Two issues:
- The blind
Exceptioncatch on line 101 is too broad. - Form fields might be
UploadFileobjects rather than strings if a client uploads a file under a field name liketweaks. This could cause downstream validation errors.
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)
src/backend/base/langflow/api/v1/endpoints.py:101:28: BLE001 Do not catch blind exception: Exception
[failure] 100-100: Ruff (E501)
src/backend/base/langflow/api/v1/endpoints.py:100:121: E501 Line too long (121 > 120)
| raw_tweaks = form.get("tweaks") | ||
| if raw_tweaks: | ||
| try: | ||
| data["tweaks"] = orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks |
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:
- data["tweaks"] = orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks
+ data["tweaks"] = (
+ orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| data["tweaks"] = orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else raw_tweaks | |
| data["tweaks"] = ( | |
| orjson.loads(raw_tweaks) if isinstance(raw_tweaks, (str, bytes)) else 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] 100-100: Ruff (E501)
src/backend/base/langflow/api/v1/endpoints.py:100:121: E501 Line too long (121 > 120)
🤖 Prompt for AI Agents
In src/backend/base/langflow/api/v1/endpoints.py around line 100, the single
line assigning data["tweaks"] exceeds the 120-character limit; break it into
multiple shorter lines so it fits the style guide. Specifically, compute
orjson.loads(raw_tweaks) only when raw_tweaks is a str or bytes and assign to
data["tweaks"] using a conditional expression split across lines (or use an
intermediate variable) so no line is longer than 120 characters and behavior
remains identical.
…to support session_id (fix langflow-ai#9859) changes made as per coderabbitai
|
Hello! I noticed the autofix.ci check is failing and I'm not sure if it requires action from me or if it's an automated issue. Could someone advise on how to proceed? Appreciate your help! |
Problem
Requests containing both text and image data (sent as
multipart/form-data) while including asession_idcaused a server error (IndexError/500). The server incorrectly attempted to parse the request body as pure JSON, which consumed themultipart/form-datastream and led to missing input fields downstream.Change
The logic in
parse_input_request_from_bodyhas been updated to correctly handle different content types:Content-Type.Content-Typeismultipart/form-data, it now usesawait request.form()to correctly parse the data, extract expected form fields (includingsession_id), and map them into aSimplifiedAPIRequest.application/jsonrequests is preserved (no change in behavior for standard JSON requests).SimplifiedAPIRequestis returned on error, maintaining the previous error-handling behavior.Why This Fixes It
Multipart requests are now parsed correctly via
request.form(). This ensures that file streams and form fields (likesession_id) are preserved. Downstream processing code no longer encounters an empty inputs list, which was the root cause of theIndexError.Files Changed
parse_input_request_from_bodyTests
Fixes: #9859
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.