fix: strip reserved 'code' param before build() in component reuse path#12712
Merged
erichare merged 4 commits intoMay 11, 2026
Merged
Conversation
Contributor
WalkthroughThis PR fixes a bug where the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 4 warnings)
✅ Passed checks (4 passed)
✨ 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 |
aayushbaluni
added a commit
to aayushbaluni/langflow
that referenced
this pull request
Apr 15, 2026
Verifies that TypeError no longer occurs when reusing custom components with the code parameter in both instantiate and reuse paths. Per CodeRabbit review on PR langflow-ai#12712. Made-with: Cursor
c8d48e4 to
447f375
Compare
aayushbaluni
added a commit
to aayushbaluni/langflow
that referenced
this pull request
Apr 26, 2026
Verifies that TypeError no longer occurs when reusing custom components with the code parameter in both instantiate and reuse paths. Per CodeRabbit review on PR langflow-ai#12712. Made-with: Cursor
…th (langflow-ai#8610) Root cause: When a custom component is reused (self.custom_component already exists), get_params() returns params that still include the reserved 'code' field. Unlike the instantiate_class path which pops 'code' before use, the reuse path passes it through to build_custom_component, which calls build(**params) — causing TypeError for components whose build() method does not accept **kwargs. Made-with: Cursor
Verifies that TypeError no longer occurs when reusing custom components with the code parameter in both instantiate and reuse paths. Per CodeRabbit review on PR langflow-ai#12712. Made-with: Cursor
Mirror the lfx fix in the parallel src/backend/base/langflow/interface/ initialize/loading.py copy. In production this build_custom_component is dead code (only update_params_with_load_from_db_fields is imported from this module), but keeping the duplicate in sync avoids future drift and the same TypeError if any caller starts using it.
447f375 to
e7f2597
Compare
4 tasks
erichare
approved these changes
May 11, 2026
erichare
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thank you @aayushbaluni
Merged
via the queue into
langflow-ai:release-1.10.0
with commit May 11, 2026
5c111a1
295 of 301 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8610 and the duplicate report at #13067.
Root cause: When a custom component is reused (
self.custom_componentalready exists on the vertex), the else branch ofVertex._buildcallsget_params(self.params)and passes the result straight intobuild_custom_component, which callsbuild(**params). Unlike theinstantiate_classpath — which popscodebefore use — the reuse path leaks the syntheticcodetemplate field through tobuild(), raising:for any legacy
CustomComponentwhosebuild()signature doesn't accept**kwargs(e.g. a customMiddlewareComponent/PolicyCheckwithdef build(self, api_key, middleware_url, user_request)).Modern
Componentsubclasses use output methods and aren't affected, which is why this slipped through.Fix
Three defensive
params.pop("code", None)insertions so both code paths consistently strip the reservedcodefield before callingbuild():src/lfx/src/lfx/graph/vertex/base.py— reuse branch of_build, right afterget_params().src/lfx/src/lfx/interface/initialize/loading.py— top ofbuild_custom_component()(catches any other caller that forgets to strip).src/backend/base/langflow/interface/initialize/loading.py— same defensive strip in the parallelbuild_custom_component()copy. In production this duplicate is dead code (onlyupdate_params_with_load_from_db_fieldsis imported from it viaendpoints.py), but keeping it in sync avoids future drift.Testing
src/lfx/tests/unit/interface/test_loading_custom_component_code_param.pycovering:build()signature withcodein params.build()signature withcodein params.code: Noneand missing-codevariants (pop must be safe).get_paramsreuse-path semantics.test_loading.pytests still pass.Branch
Rebased onto
release-1.10.0(was previously onmain) to target the active release branch.Notes
This PR does not address the separate "Message → str" connection-compatibility complaint from #13067's bug report; that's a frontend type-system issue with a different root cause and should be triaged separately.
Made with Cursor
Summary by CodeRabbit