Skip to content

fix: strip 'code' field from custom component build params#13067

Closed
erichare wants to merge 1 commit into
release-1.10.0from
fix/legacy-custom-component-code-kwarg
Closed

fix: strip 'code' field from custom component build params#13067
erichare wants to merge 1 commit into
release-1.10.0from
fix/legacy-custom-component-code-kwarg

Conversation

@erichare

Copy link
Copy Markdown
Collaborator

Summary

Fixes TypeError: <Component>.build() got an unexpected keyword argument 'code' for legacy CustomComponent subclasses (e.g. a custom MiddlewareComponent / PolicyCheck component).

Root cause

When a graph is loaded, Graph._instantiate_components_in_vertices() pre-instantiates every vertex's component and stores it on vertex.custom_component. Later, when Vertex._build() runs, self.custom_component is truthy, so it takes the else branch:

custom_params = initialize.loading.get_params(self.params)

get_params() never stripped the synthetic code template field — only instantiate_class() did, via a local custom_params.pop("code"). So in the reused-component path, code leaked through to build_custom_component(), which calls custom_component.build(**params).

For legacy CustomComponent subclasses with an explicit signature like:

def build(self, api_key, middleware_url, user_request):
    ...

Python raised TypeError: MiddlewareComponent.build() got an unexpected keyword argument 'code'. Modern Component subclasses (which use output methods, not build) were unaffected, which is why this slipped through.

Fix

  • get_params() now drops "code" from the returned copy (single point of truth).
  • instantiate_class() reads code from vertex.params directly before calling get_params() so class evaluation still works.
  • Applied symmetrically to both copies: src/lfx/.../loading.py and src/backend/base/langflow/.../loading.py.

Test plan

  • New unit tests: test_get_params_strips_code_field, test_get_params_without_code_field_is_unchanged in src/backend/tests/unit/interface/initialize/test_loading.py.
  • Full test_loading.py suite passes (17/17).
  • Manual repro: build a legacy CustomComponent with def build(self, api_key, middleware_url, user_request), wire to a Text Input, and run — should no longer raise.
  • CI green on this branch.

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.

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.
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b9604ed-c77f-4327-acc8-d0f3d48cb757

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/legacy-custom-component-code-kwarg

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label May 11, 2026
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.43%. Comparing base (80d0db3) to head (e0b8977).
⚠️ Report is 4 commits behind head on release-1.10.0.

Files with missing lines Patch % Lines
...kend/base/langflow/interface/initialize/loading.py 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Flag Coverage Δ
backend 58.40% <0.00%> (+0.78%) ⬆️
frontend 54.36% <ø> (-0.56%) ⬇️
lfx 50.75% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/lfx/src/lfx/interface/initialize/loading.py 32.83% <100.00%> (+0.67%) ⬆️
...kend/base/langflow/interface/initialize/loading.py 22.41% <0.00%> (-0.40%) ⬇️

... and 252 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erichare

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #12712, which fixes the same underlying bug and predates this PR. I've rebased #12712 onto release-1.10.0 and added one extra commit there to keep the parallel src/backend/base/langflow/interface/initialize/loading.py copy in sync (defensive params.pop("code", None) in its build_custom_component). That backend duplicate isn't called in production today, but syncing it avoids future drift.

Please follow up on #12712.

@github-actions

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 37%
37.86% (45640/120544) 67.44% (6261/9283) 37.55% (1050/2796)

Unit Test Results

Tests Skipped Failures Errors Time
4229 0 💤 0 ❌ 0 🔥 8m 30s ⏱️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant