From 1a4adaceb886d8950eff655bd0abd5ed0b5e934d Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Wed, 14 May 2025 14:27:13 -0300 Subject: [PATCH] fix: Avoid unnecessary field resets in the API Request component (#7544) * Add a logic to skip field reset if curl is not used * Remove the else clause to avoid setting all other fields to advanced * Fix return type * Add a logic to avoid setting a field to advanced when use_curl is not defined * Refactor else logic of _update_method_fields and _update_curl_mode * Rollback _update_method_fields changes * Return the current build config instead of an empty dict --------- Co-authored-by: Edwin Jose Co-authored-by: Gabriel Luiz Freitas Almeida --- src/backend/base/langflow/components/data/api_request.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/components/data/api_request.py b/src/backend/base/langflow/components/data/api_request.py index 3edc8bea6..1697a6972 100644 --- a/src/backend/base/langflow/components/data/api_request.py +++ b/src/backend/base/langflow/components/data/api_request.py @@ -287,6 +287,10 @@ class APIRequestComponent(Component): # if we remove field value from validation, this gets validated every time build_config = self._update_curl_mode(build_config, use_curl=field_value) + # If curl is not used, we don't need to reset the fields + if not self.use_curl: + return build_config + # Fields that should not be reset preserve_fields = {"timeout", "follow_redirects", "save_to_file", "include_httpx_metadata", "use_curl"} @@ -336,7 +340,7 @@ class APIRequestComponent(Component): elif field_name in {"body", "headers"}: field_config["advanced"] = True # Always keep body and headers in advanced when use_curl is False else: - field_config["advanced"] = use_curl + field_config["advanced"] = use_curl or field_config.get("advanced") else: self.log(f"Expected dict for build_config[{field_name}], got {type(field_config).__name__}") @@ -374,8 +378,6 @@ class APIRequestComponent(Component): field_config["advanced"] = method not in {"POST", "PUT", "PATCH"} elif field_name in always_advanced_fields: field_config["advanced"] = True - else: - field_config["advanced"] = True else: self.log(f"Expected dict for build_config[{field_name}], got {type(field_config).__name__}")