fix: strip 'code' field from custom component build params#13067
fix: strip 'code' field from custom component build params#13067erichare wants to merge 1 commit into
Conversation
When a graph is loaded, _instantiate_components_in_vertices pre-instantiates every vertex's component. On subsequent Vertex._build() runs, since self.custom_component is already set, the else branch in _build calls get_params(self.params), which never stripped the synthetic 'code' template field. The instantiate_class path stripped it; the reused-component path did not. For legacy CustomComponent subclasses with an explicit build signature (e.g. def build(self, api_key, middleware_url, user_request)), the leaked 'code' kwarg surfaced as: TypeError: <Cls>.build() got an unexpected keyword argument 'code' Move the pop into get_params (single point of truth) and read 'code' from vertex.params directly inside instantiate_class so class evaluation still works. Applied to both the lfx and backend/base/langflow copies.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-1.10.0 #13067 +/- ##
==================================================
- Coverage 54.69% 54.43% -0.26%
==================================================
Files 2101 2102 +1
Lines 192799 193590 +791
Branches 29257 28893 -364
==================================================
- Hits 105443 105381 -62
- Misses 86186 87040 +854
+ Partials 1170 1169 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Closing in favor of #12712, which fixes the same underlying bug and predates this PR. I've rebased #12712 onto Please follow up on #12712. |
Summary
Fixes
TypeError: <Component>.build() got an unexpected keyword argument 'code'for legacyCustomComponentsubclasses (e.g. a customMiddlewareComponent/PolicyCheckcomponent).Root cause
When a graph is loaded,
Graph._instantiate_components_in_vertices()pre-instantiates every vertex's component and stores it onvertex.custom_component. Later, whenVertex._build()runs,self.custom_componentis truthy, so it takes the else branch:get_params()never stripped the syntheticcodetemplate field — onlyinstantiate_class()did, via a localcustom_params.pop("code"). So in the reused-component path,codeleaked through tobuild_custom_component(), which callscustom_component.build(**params).For legacy
CustomComponentsubclasses with an explicit signature like:Python raised
TypeError: MiddlewareComponent.build() got an unexpected keyword argument 'code'. ModernComponentsubclasses (which use output methods, notbuild) were unaffected, which is why this slipped through.Fix
get_params()now drops"code"from the returned copy (single point of truth).instantiate_class()readscodefromvertex.paramsdirectly before callingget_params()so class evaluation still works.src/lfx/.../loading.pyandsrc/backend/base/langflow/.../loading.py.Test plan
test_get_params_strips_code_field,test_get_params_without_code_field_is_unchangedinsrc/backend/tests/unit/interface/initialize/test_loading.py.test_loading.pysuite passes (17/17).CustomComponentwithdef build(self, api_key, middleware_url, user_request), wire to a Text Input, and run — should no longer raise.Notes
This PR does not address the separate "Message → str" connection-compatibility complaint from the original bug report; that's a frontend type-system issue with a different root cause and should be triaged separately.