fix: api request component curl mode error#8353
Conversation
## Walkthrough
The `update_build_config` method in `APIRequestComponent` was updated to handle changes to the `"curl_input"` field when the mode is set to `"cURL"`. The method now parses the cURL input and updates the configuration immediately when relevant fields change, with added checks for non-empty input.
## Changes
| File | Change Summary |
|-------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| src/backend/base/langflow/components/data/api_request.py | Modified `update_build_config` to handle `"curl_input"` changes in `"cURL"` mode and add input checks.|
| src/backend/base/langflow/initial_setup/starter_projects/... | Updated embedded `APIRequestComponent` code in JSON to reflect the same `update_build_config` logic.|
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant APIRequestComponent
User->>APIRequestComponent: update_build_config(field_name, field_value, build_config)
alt field_name is "mode" and field_value is "cURL" and curl_input exists and not empty
APIRequestComponent->>APIRequestComponent: parse curl_input
APIRequestComponent-->>User: return updated build_config
else field_name is "curl_input" and mode is "cURL" and field_value not empty
APIRequestComponent->>APIRequestComponent: parse field_value as curl_input
APIRequestComponent-->>User: return updated build_config
else
APIRequestComponent-->>User: return updated build_config (no parsing)
end |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/backend/base/langflow/components/data/api_request.py (1)
459-460: Good addition but consider consistency with the mode change logic.The new logic correctly handles immediate parsing when the
curl_inputfield changes. However, there's an inconsistency in how the curl input value is accessed compared to the mode change logic below.Consider using a consistent approach for accessing the curl input value:
-if field_name == "curl_input" and self.mode == "cURL" and self.curl_input: - return self.parse_curl(self.curl_input, build_config) +if field_name == "curl_input" and self.mode == "cURL" and build_config["curl_input"]["value"]: + return self.parse_curl(build_config["curl_input"]["value"], build_config)This ensures consistency with how the curl input is accessed in the mode change logic and uses the most up-to-date value from the build config.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/backend/base/langflow/components/data/api_request.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/backend/base/langflow/components/data/api_request.py (1)
src/backend/base/langflow/utils/component_utils.py (1)
set_field_display(56-60)
🔇 Additional comments (1)
src/backend/base/langflow/components/data/api_request.py (1)
466-467: Excellent defensive programming improvement.The added conditional check prevents unnecessary parsing when there's no curl input value, which is a good defensive programming practice.
| if field_name == "curl_input" and self.mode == "cURL" and self.curl_input: | ||
| return self.parse_curl(self.curl_input, build_config) | ||
| return build_config |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Verify error handling for parse_curl exceptions.
The early return on line 460 bypasses the rest of the method's logic that handles field visibility and advanced settings. While this may be intentional, ensure that:
- The
parse_curlmethod's potential exceptions are properly handled by the calling code - The early return doesn't skip any necessary UI configuration updates
Let me check how exceptions from parse_curl are handled in the calling context:
🏁 Script executed:
#!/bin/bash
# Description: Check how update_build_config is called and if exceptions are handled
# Expected: Find callers and see if they have try-catch blocks
# Search for calls to update_build_config method
rg -A 10 -B 5 "update_build_config" --type py
# Also search for any exception handling around these calls
rg -A 5 -B 5 "try.*update_build_config|update_build_config.*except" --type pyLength of output: 65661
Add robust error handling for parse_curl in update_build_config
Wrap the call to self.parse_curl in a try/except so that any parsing errors don’t bubble up and skip the rest of the UI‐update logic. For example, in src/backend/base/langflow/components/data/api_request.py around lines 459–461:
- if field_name == "curl_input" and self.mode == "cURL" and self.curl_input:
- return self.parse_curl(self.curl_input, build_config)
- return build_config
+ if field_name == "curl_input" and self.mode == "cURL" and self.curl_input:
+ try:
+ return self.parse_curl(self.curl_input, build_config)
+ except Exception as e:
+ logger.error("Failed to parse cURL input: %s", e)
+ # Fallback to original build_config so other UI logic still runs
+ return build_config
+ return build_config• Ensures parse errors are logged and won’t break the remaining visibility/advanced‐settings updates
• Guarantees the method always returns a valid build_config
📝 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.
| if field_name == "curl_input" and self.mode == "cURL" and self.curl_input: | |
| return self.parse_curl(self.curl_input, build_config) | |
| return build_config | |
| if field_name == "curl_input" and self.mode == "cURL" and self.curl_input: | |
| try: | |
| return self.parse_curl(self.curl_input, build_config) | |
| except Exception as e: | |
| logger.error("Failed to parse cURL input: %s", e) | |
| # Fallback to original build_config so other UI logic still runs | |
| return build_config | |
| return build_config |
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/data/api_request.py around lines 459 to
461, the call to self.parse_curl is returned early without handling potential
exceptions, which may cause parse errors to propagate and skip subsequent UI
configuration updates. To fix this, wrap the call to self.parse_curl in a
try/except block that catches any exceptions, logs the error, and ensures the
method continues to execute the remaining logic before returning a valid
build_config.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (2)
925-926: 🔧 Handle emptycurl_inputto avoid stale data
If the user clears the curl command (i.e. setscurl_inputto an empty string), the previous URL, headers, and body remain in the config. It’d be safer to detect whencurl_inputis blank and reset those fields. For example:def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict: - if field_name == "curl_input" and self.mode == "cURL" and self.curl_input: - return self.parse_curl(self.curl_input, build_config) + if field_name == "curl_input" and self.mode == "cURL": + if self.curl_input: + return self.parse_curl(self.curl_input, build_config) + # Reset when cleared + build_config["url_input"]["value"] = "" + build_config["headers"]["value"] = [] + build_config["body"]["value"] = [] + return build_config
925-926: 🧪 Add unit tests forparse_curl
To guard against regressions, consider writing tests that:
- Feed valid curl strings and assert the resulting
build_configfields match expectations.- Feed malformed curl strings and verify a
ValueErroris raised.
Would you like assistance generating those test cases?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Optimize new Python code in this PR
- GitHub Check: Update Starter Projects
- GitHub Check: Run Ruff Check and Format
- GitHub Check: Ruff Style Check (3.13)
🔇 Additional comments (1)
src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (1)
925-926: ✅ Good addition of cURL parsing workflow
The newparse_curlmethod and the extendedupdate_build_configcheck for"curl_input"under"cURL"mode correctly wire up URL, method, headers, and body fields whenever the user pastes a curl command. This makes the component far more responsive and modular.
* Update api_request.py * Update api_request.py * [autofix.ci] apply automated fixes * Update Pokédex Agent.json --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Hare <ericrhare@gmail.com>
* Update api_request.py * Update api_request.py * [autofix.ci] apply automated fixes * Update Pokédex Agent.json --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Hare <ericrhare@gmail.com>
This pull request introduces enhancements to the
src/backend/base/langflow/components/data/api_request.pyfile, focusing on improving the handling of cURL input in API requests. The most significant changes involve adding logic to parse cURL input and update the build configuration dynamically based on the selected mode.Enhancements to cURL input handling:
src/backend/base/langflow/components/data/api_request.py: Introduced a call toparse_curlin theupdate_build_configmethod to processcurl_inputwhen the mode is set to "cURL" andcurl_inputis provided. This ensures the build configuration is updated appropriately.src/backend/base/langflow/components/data/api_request.py: Added theparse_curlmethod, which parses a cURL command and updates the build configuration. This method improves modularity and readability for handling cURL inputs.Summary by CodeRabbit