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 <edwin.jose@datastax.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Thiago Araujo 2025-05-14 14:27:13 -03:00 committed by GitHub
commit 1a4adaceb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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__}")