fix: change lambda filter to smart function#8558
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes rename the LambdaFilterComponent to SmartFunctionComponent across the codebase and documentation. Imports, exports, class names, and references are updated accordingly. The DataFrame output and related method are removed from the component. Associated documentation and tests are also updated to reflect the new component name. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SmartFunctionComponent
User->>SmartFunctionComponent: Provide structured data and filter/transform function
SmartFunctionComponent->>SmartFunctionComponent: Generate and validate lambda function
SmartFunctionComponent->>SmartFunctionComponent: Apply function to data
SmartFunctionComponent-->>User: Return filtered/transformed data
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
Build successful! ✅ |
1 similar comment
|
Build successful! ✅ |
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (3)
src/backend/base/langflow/components/processing/__init__.py (1)
14-20: Missing import forParseDataFrameComponent
ParseDataFrameComponentis still exposed in__all__(lines 37-38) but the corresponding import statement is absent. Any runtime code that performsfrom langflow.components.processing import ParseDataFrameComponentwill raiseImportError.from .parse_json_data import ParseJSONDataComponent +from .parse_dataframe import ParseDataFrameComponent from .parser import ParserComponentdocs/docs/Components/components-processing.md (1)
291-297: Docs expose aDataFrameoutput that no longer exists
SmartFunctionComponent.outputsnow only contains"filtered_data", but the table still lists adataframeoutput. Update the docs or re-add the output implementation to stay consistent.src/backend/base/langflow/components/processing/smart_function.py (1)
140-142:evalon LLM-generated code is a high-risk security holeBlindly evaluating arbitrary code from an external model can lead to RCE. At minimum, run
evalwith an empty__builtins__, or better, execute in a sandbox such asast.literal_eval/numexpr, or disallow anything except list/dict comprehensions.safe_globals: dict[str, Any] = {"__builtins__": {}} fn = eval(lambda_text, safe_globals, {})
🧹 Nitpick comments (5)
src/backend/tests/unit/components/processing/test_lambda_filter.py (1)
10-14: Rename the test class for clarityThe class is still called
TestLambdaFilterComponent, which no longer matches the component under test and will confuse future readers.-class TestLambdaFilterComponent(ComponentTestBaseWithoutClient): +class TestSmartFunctionComponent(ComponentTestBaseWithoutClient):docs/docs/Components/components-processing.md (2)
24-33: Doc/image still references Lambda assetLine 276 embeds
/img/component-lambda-filter.png, but the component was renamed.
Rename the asset (or update the path) to avoid broken images and inconsistent wording.
34-34: Specify fenced-code languageMarkdown-lint flags this line (
```) because the language is missing.-``` +```textsrc/backend/base/langflow/components/processing/smart_function.py (2)
71-74: Method shadowing causes confusionThe method is named
get_data_structure, identical to the imported helper.
Inside the body you purposefully call the global helper, but readers will expect a recursive call toself.get_data_structure.- def get_data_structure(self, data): + def _build_data_structure(self, data): """Extract the structure of a dictionary, replacing values with their types.""" - return {k: get_data_structure(v) for k, v in data.items()} + return {k: get_data_structure(v) for k, v in data.items()}Adjust call sites (
self._build_data_structure) accordingly.
135-139: Comment contradicts codeThe comment says “Validation is commented out”, yet
_validate_lambdais still executed.
Either delete the call or fix the comment to reflect reality.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
docs/docs/Components/components-processing.md(2 hunks)src/backend/base/langflow/components/processing/__init__.py(2 hunks)src/backend/base/langflow/components/processing/smart_function.py(1 hunks)src/backend/tests/unit/components/processing/test_lambda_filter.py(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/backend/base/langflow/components/processing/__init__.py (1)
src/backend/base/langflow/components/processing/smart_function.py (1)
SmartFunctionComponent(16-153)
src/backend/tests/unit/components/processing/test_lambda_filter.py (1)
src/backend/base/langflow/components/processing/smart_function.py (1)
SmartFunctionComponent(16-153)
🪛 markdownlint-cli2 (0.17.2)
docs/docs/Components/components-processing.md
34-34: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
🪛 Pylint (3.3.7)
src/backend/tests/unit/components/processing/test_lambda_filter.py
[error] 4-4: No name 'components' in module 'langflow'
(E0611)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-deploy
🔇 Additional comments (2)
src/backend/base/langflow/components/processing/__init__.py (1)
24-48: Keep__all__in sync and alphabetically orderedAfter adding
SmartFunctionComponent, the list stays alphabetically correct, but remember to insert / remove entries together with their imports to avoid the drift caught above.src/backend/tests/unit/components/processing/test_lambda_filter.py (1)
4-4: Import path triggers pylint E0611Static analysis cannot resolve
langflow.components.processing.smart_function.
If the package root islangflow, make sure it is added toPYTHONPATHin test settings; otherwise use a relative import (from ...processing.smart_function import SmartFunctionComponent) to stay package-local.
| from langflow.utils.data_structure import get_data_structure | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
|
|
||
| class LambdaFilterComponent(Component): |
There was a problem hiding this comment.
This is a superbreaking change which we cannot do. Is it highly necessary to update the component name?
There was a problem hiding this comment.
@edwinjosechittilappilly is renaming the class itself a breaking change if the code is refactored properly? i was under the impression that compatibility was derived from the name="filtered_data" parameter to the constructor?
There was a problem hiding this comment.
If changing the name of the class, it will break the connection between a component in the canvas and their sidebar counterpart. What you can do is add the name attribute to avoid that, but the best solution is to not change the name of the class, just the display name.
There was a problem hiding this comment.
The name of the component comes from the name of the class. In very old versions we got it from the name of the file, to avoid having files named OpenAIComponent we created the name attribute and set it instead to OpenAIComponent so we don't lose the connection. Now the name of the class is the standard, and the name is kept just so we serve the purpose above, so we should avoid using it to eventually remove it.
There was a problem hiding this comment.
Thank you @ogabrielluiz that makes a lot of sense! I had it kind of backwards in my head.
edwinjosechittilappilly
left a comment
There was a problem hiding this comment.
Need confirmation since it breaks without informing, since the component class name is changes @ogabrielluiz need your consult on this
|
Build failure! ❌ |
|
Build successful! ✅ |
|
Build successful! ✅ |
|
Build successful! ✅ |
1 similar comment
|
Build successful! ✅ |
|
Build successful! ✅ |
* change lambda filter nme * reverse change for lambda filter --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
* change lambda filter nme * reverse change for lambda filter --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This pull request refactors the
Lambda filtercomponent into a newSmart functioncomponent, updates related documentation, and removes unused methods and outputs from the backend implementation. The changes aim to improve clarity and streamline functionality.Documentation Updates:
Backend Code Simplification:
as_dataframemethod and its corresponding output from theLambdaFilterComponentclass, as it is no longer needed. [1] [2]DataFramefromlambda_filter.py.