fix: Run Flow component loading, building, & running in Langflow / LFX#10136
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 WalkthroughIntroduces a conditional import facade in lfx.helpers to select LangFlow or LFX implementations at import time, updates import paths across LFX modules to use lfx.helpers, re-exports UUID utilities in the backend serialize module, and removes all from lfx.helpers.flow while centralizing exports in lfx.helpers.init. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Importer
participant Helpers as lfx.helpers.__init__
participant PySpec as importlib.util.find_spec
participant LF as langflow.helpers.flow
participant LFX as lfx.helpers.flow
Importer->>Helpers: import lfx.helpers
Helpers->>PySpec: find_spec("langflow")
alt LangFlow available
Helpers->>LF: import build_schema_from_inputs, get_arg_names, get_flow_inputs, list_flows, load_flow, run_flow
note right of Helpers: On failure, fall back to LFX
else Not available
Helpers->>LFX: import same symbols
end
Helpers-->>Importer: expose symbols via __all__
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 error, 1 warning, 2 inconclusive)
✅ Passed checks (3 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/lfx/src/lfx/helpers/__init__.py (2)
31-62: Simplify redundant import fallback logic.The fallback in the exception handler (lines 42-52) and the else block (lines 53-62) both import from
lfx.helpers.flow, resulting in code duplication. This can be consolidated.Apply this diff to eliminate the duplication:
+# Default imports (used as fallback or when langflow is unavailable) +_import_source = "lfx.helpers.flow" + # Import the appropriate implementations if _LANGFLOW_AVAILABLE: try: # Import from full langflow implementation from langflow.helpers.flow import ( build_schema_from_inputs, get_arg_names, get_flow_inputs, list_flows, load_flow, run_flow, ) + _import_source = "langflow.helpers.flow" except (ImportError, ModuleNotFoundError) as e: logger.error(f"Failed to import langflow.helpers.flow: {e}") - # Fall back to lfx if langflow import fails + logger.info("Falling back to lfx.helpers.flow") + +if _import_source == "lfx.helpers.flow": + # Use lfx implementation - from lfx.helpers.flow import ( - build_schema_from_inputs, - get_arg_names, - get_flow_inputs, - list_flows, - load_flow, - run_flow, - ) -else: - # Use lfx from lfx.helpers.flow import ( build_schema_from_inputs, get_arg_names, get_flow_inputs, list_flows, load_flow, run_flow, )
25-28: Verify runtime availability concerns.The TODO comment notes that the current import-time check won't handle runtime availability changes. Since
_LANGFLOW_AVAILABLEis set once at module import, the system cannot adapt if langflow becomes available or unavailable later during execution.Consider whether your use cases require runtime switching between langflow and lfx implementations. If so, you may need to implement the lazy loading or service discovery mechanism mentioned in the TODO. If not, document that this is by design and remove the TODO.
Do you want me to generate a lazy-loading implementation that can handle runtime availability changes, or would you prefer to keep the current import-time approach and update the comment accordingly?
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
src/backend/base/langflow/schema/serialize.py(1 hunks)src/lfx/src/lfx/base/tools/flow_tool.py(1 hunks)src/lfx/src/lfx/base/tools/run_flow.py(1 hunks)src/lfx/src/lfx/components/deactivated/sub_flow.py(1 hunks)src/lfx/src/lfx/components/logic/flow_tool.py(1 hunks)src/lfx/src/lfx/components/logic/run_flow.py(1 hunks)src/lfx/src/lfx/components/logic/sub_flow.py(1 hunks)src/lfx/src/lfx/custom/custom_component/custom_component.py(1 hunks)src/lfx/src/lfx/helpers/__init__.py(1 hunks)src/lfx/src/lfx/helpers/flow.py(0 hunks)
💤 Files with no reviewable changes (1)
- src/lfx/src/lfx/helpers/flow.py
🧰 Additional context used
📓 Path-based instructions (1)
{src/backend/**/*.py,tests/**/*.py,Makefile}
📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)
{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code
Files:
src/backend/base/langflow/schema/serialize.py
🧬 Code graph analysis (8)
src/lfx/src/lfx/components/deactivated/sub_flow.py (1)
src/lfx/src/lfx/helpers/flow.py (1)
get_flow_inputs(20-29)
src/lfx/src/lfx/components/logic/flow_tool.py (1)
src/lfx/src/lfx/helpers/flow.py (1)
get_flow_inputs(20-29)
src/lfx/src/lfx/custom/custom_component/custom_component.py (1)
src/lfx/src/lfx/helpers/flow.py (3)
list_flows(66-85)load_flow(88-115)run_flow(118-191)
src/lfx/src/lfx/base/tools/run_flow.py (1)
src/lfx/src/lfx/helpers/flow.py (1)
get_flow_inputs(20-29)
src/lfx/src/lfx/components/logic/sub_flow.py (1)
src/lfx/src/lfx/helpers/flow.py (1)
get_flow_inputs(20-29)
src/lfx/src/lfx/base/tools/flow_tool.py (2)
src/lfx/src/lfx/helpers/flow.py (4)
build_schema_from_inputs(32-47)get_arg_names(50-63)get_flow_inputs(20-29)run_flow(118-191)src/lfx/src/lfx/custom/custom_component/custom_component.py (1)
run_flow(528-544)
src/lfx/src/lfx/helpers/__init__.py (2)
src/lfx/src/lfx/helpers/flow.py (6)
build_schema_from_inputs(32-47)get_arg_names(50-63)get_flow_inputs(20-29)list_flows(66-85)load_flow(88-115)run_flow(118-191)src/lfx/src/lfx/custom/custom_component/custom_component.py (3)
list_flows(546-548)load_flow(522-526)run_flow(528-544)
src/lfx/src/lfx/components/logic/run_flow.py (2)
src/lfx/src/lfx/custom/custom_component/custom_component.py (1)
run_flow(528-544)src/lfx/src/lfx/helpers/flow.py (1)
run_flow(118-191)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 11/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 6/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 2/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 8/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 7/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 12/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 10/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 5/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 9/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 13/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 1/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 4/13
- GitHub Check: Run Frontend Tests / Playwright Tests - Shard 3/13
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
- GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
- GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
- GitHub Check: Test Starter Templates
🔇 Additional comments (8)
src/backend/base/langflow/schema/serialize.py (1)
1-4: LGTM! Clean re-export pattern.The re-export of UUID utilities from lfx.schema.serialize maintains a clean API boundary and follows the facade pattern consistently.
src/lfx/src/lfx/components/logic/flow_tool.py (1)
9-9: LGTM! Import path update is consistent.This change aligns with the centralized helper import strategy. Verification of the
lfx.helpersexport surface has been requested in a previous comment.src/lfx/src/lfx/components/logic/run_flow.py (1)
4-4: LGTM! Import path update is consistent.The import change aligns with the centralized helper strategy. The
run_flowfunction usage on line 63 remains unchanged.src/lfx/src/lfx/custom/custom_component/custom_component.py (1)
15-15: LGTM! Import consolidation is consistent.All three helper functions (
list_flows,load_flow,run_flow) are now imported from the centralizedlfx.helpersmodule. Their usage throughout the file (lines 526, 536, 555) remains unchanged.src/lfx/src/lfx/base/tools/run_flow.py (1)
8-8: LGTM! Import path update is consistent.The import change aligns with the centralized helper strategy. Usage on line 135 remains unchanged.
src/lfx/src/lfx/base/tools/flow_tool.py (1)
9-9: LGTM! Import consolidation is consistent.All four helper functions (
build_schema_from_inputs,get_arg_names,get_flow_inputs,run_flow) are now imported from the centralizedlfx.helpersmodule. Their usage throughout the file (lines 44, 54, 99, 115) remains unchanged.src/lfx/src/lfx/components/deactivated/sub_flow.py (1)
7-7: LGTM! Import path update is consistent.The import change aligns with the centralized helper strategy. Note that this component is in the
deactivatedfolder, suggesting it may be legacy code maintained for backward compatibility.src/lfx/src/lfx/components/logic/sub_flow.py (1)
7-7: Verified export of get_flow_inputs –lfx.helpers/__init__.pyincludesget_flow_inputsin its__all__, so the import path change is valid.
a385f86 to
12d8854
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (48.70%) is below the target coverage (55.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10136 +/- ##
==========================================
+ Coverage 24.14% 24.76% +0.62%
==========================================
Files 1088 1089 +1
Lines 40093 40095 +2
Branches 5548 5548
==========================================
+ Hits 9680 9930 +250
+ Misses 30242 29994 -248
Partials 171 171
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
103baf5 to
80ad0c0
Compare
988dfa4 to
948a3cb
Compare
- Add 6 test scnearios for LFX - Add 6 test scenarios for Langflow
- Address PR comments from Code Review 1: (c), (e), (f)
- Fix test scenario failure: src/backend/tests/unit/test_lfx_reexport_modules.py::TestLfxReexportModules.test_generate_backward_compatibility_imports
948a3cb to
ad7c310
Compare
|



Overview
Manual Tests
Test Run: LFX
Test Run: Langflow
Summary by CodeRabbit
Refactor
Chores