Skip to content

fix: api request component curl mode error#8353

Merged
edwinjosechittilappilly merged 6 commits into
mainfrom
fix-api-request-curl-command
Jun 3, 2025
Merged

fix: api request component curl mode error#8353
edwinjosechittilappilly merged 6 commits into
mainfrom
fix-api-request-curl-command

Conversation

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly commented Jun 3, 2025

This pull request introduces enhancements to the src/backend/base/langflow/components/data/api_request.py file, 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:

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of cURL input updates in API request configuration, ensuring immediate parsing and validation when changes occur in cURL mode.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 3, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2025

## 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

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between afb164559562f7622718c2eccf34d349c8fd3b74 and 0ec3740ccd556b0b136eee39f15646543dd5bb51.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json` (1 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (4)</summary>

* GitHub Check: Optimize new Python code in this PR
* GitHub Check: Ruff Style Check (3.13)
* GitHub Check: Update Starter Projects
* GitHub Check: Run Ruff Check and Format

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIAM3gADy40bh1/IJCFZm58cgxQhmwKX2ZFD0oKfApoyDlIbERKSDoAd3gMIXxGhgRccS8U1J95NFpaf0RG5Hhsyqk2fOmsXFgPWExaL3aifljGAFUbABkUDG48SDaV9rDVyABBKwBJP0DgxAKWHLzQ/D2VjxHTBEWJefAtHiVERiDSQADK3FE8HiDDQwwANLcPD1gdJILF8IVkLksfj4JFIAADRAUBgAegEaAYAGsyLQGWhGnSBhgQWCWnSmNlcuxEHTaNQ0HSUvAAPrpd6abiySkaIwAaRI8jI6wwDBIC1wSwYXmwSlJo1o6ngJL+6Eg5AhbBWikxlO4zkassKxUpmJaCB6PE9eLQB2OWWYG3QGHo2G4EpoyABtWw5PoTAw8SIRWoNqwTKYFCtvK8slhcFQztgimaGF1+uTd1K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VWc7VSM6hkK0EQAdTCJBkFngcY/CaU1osAAYAAcAAmAAbLEbCABWAAnGV2geWADsDBqsqBICVkrWXctoAKzlgAzCV2gWWOsMCywwAQABGPLsQssZYMNF3Bw2CsABYmtlZKwV0b1Xls1aGzlhgeXRAMFiB12btB9tlYYDl4rHWBDVdmxN7LogOuXYGwwWgTWCsCCy8NjrBWSBfY62V2IQ2luzYKyV2bHWxgldUCVobE3JuJRi7gOLCWmXJboLKZK+ggA=== -->

<!-- internal state end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=langflow-ai/langflow&utm_content=8353):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@github-actions github-actions Bot added the bug Something isn't working label Jun 3, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 3, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 3, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_input field 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

📥 Commits

Reviewing files that changed from the base of the PR and between f835a6b and 0826fde.

📒 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.

Comment on lines +459 to 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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:

  1. The parse_curl method's potential exceptions are properly handled by the calling code
  2. 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 py

Length 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.

Suggested change
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.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 3, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (2)

925-926: 🔧 Handle empty curl_input to avoid stale data
If the user clears the curl command (i.e. sets curl_input to an empty string), the previous URL, headers, and body remain in the config. It’d be safer to detect when curl_input is 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 for parse_curl
To guard against regressions, consider writing tests that:

  • Feed valid curl strings and assert the resulting build_config fields match expectations.
  • Feed malformed curl strings and verify a ValueError is raised.
    Would you like assistance generating those test cases?
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0826fde and afb1645.

📒 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 new parse_curl method and the extended update_build_config check 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.

@ogabrielluiz ogabrielluiz added the fast-track Skip tests and sends PR into the merge queue label Jun 3, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 3, 2025
Copy link
Copy Markdown
Contributor

@Yukiyukiyeah Yukiyukiyeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 3, 2025
@github-actions github-actions Bot removed the bug Something isn't working label Jun 3, 2025
@github-actions github-actions Bot added the bug Something isn't working label Jun 3, 2025
@edwinjosechittilappilly edwinjosechittilappilly added this pull request to the merge queue Jun 3, 2025
Merged via the queue into main with commit 644bc87 Jun 3, 2025
18 of 20 checks passed
@edwinjosechittilappilly edwinjosechittilappilly deleted the fix-api-request-curl-command branch June 3, 2025 23:23
ogabrielluiz pushed a commit that referenced this pull request Jun 4, 2025
* 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>
ogabrielluiz pushed a commit to bkatya2001/langflow that referenced this pull request Jun 24, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fast-track Skip tests and sends PR into the merge queue lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants