feat: add dependencies, improves error handling in global scope and adds tests#9865
feat: add dependencies, improves error handling in global scope and adds tests#9865ogabrielluiz merged 9 commits intomainfrom
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 Pre-merge checks✅ 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 (5)
src/lfx/src/lfx/custom/validate.py (3)
350-354: Use _import_module_with_warnings for consistency and to suppress known deprecation noise.Direct
importlib.import_modulehere bypasses your_import_module_with_warningslogic (used below for ImportFrom), soimport langchain...via plain imports may emit avoidable warnings and behave inconsistently withfrom ... import ....- # Let importlib.import_module raise its own ModuleNotFoundError with the actual missing module - exec_globals[variable_name] = importlib.import_module(module_name) + # Let import errors propagate, but keep warning behavior consistent with ImportFrom + exec_globals[variable_name] = _import_module_with_warnings(module_name)
379-384: Raising the “last” error can mislead when trying langflow→lfx fallbacks. Provide aggregated context and chain the cause.If both imports fail, the last attempt will be
lfx.*, masking that user code importedlangflow.*. Emit an error listing all attempts and chain the original cause for debuggability.- # Re-raise the last error to preserve the actual missing module information - if last_error: - raise last_error - msg = f"Module {node.module} not found. Please install it and try again" - raise ModuleNotFoundError(msg) + # Provide context of all attempts and preserve original traceback as cause + if last_error: + attempts = ", ".join(module_names_to_try) + raise ModuleNotFoundError( + f"Unable to import from any of: {attempts}. Last error: {last_error}" + ) from last_error + raise ModuleNotFoundError(f"Module {node.module} not found. Please install it and try again.")
311-321: Align ImportFrom attribute errors with Python semantics (“cannot import name ...”).When a base module exists but an attribute doesn’t, current logic escalates to
ModuleNotFoundError(formodule.attr) instead of the idiomaticImportError: cannot import name 'attr' from 'module'. This makes diagnostics noisier and can trip consumers relying on error type.def _handle_module_attributes(imported_module, node, module_name, exec_globals): """Handle importing specific attributes from a module.""" for alias in node.names: try: # First try getting it as an attribute exec_globals[alias.name] = getattr(imported_module, alias.name) except AttributeError: - # If that fails, try importing the full module path - full_module_path = f"{module_name}.{alias.name}" - exec_globals[alias.name] = importlib.import_module(full_module_path) + # If that fails, try importing a submodule with the same name. + full_module_path = f"{module_name}.{alias.name}" + try: + exec_globals[alias.name] = importlib.import_module(full_module_path) + except ModuleNotFoundError as e: + # Match standard Python error semantics for missing attribute imports. + raise ImportError(f"cannot import name '{alias.name}' from '{module_name}'") from esrc/lfx/tests/unit/cli/test_run_starter_projects.py (2)
16-16: Stabilize CLI tests by forcing a local SQLite DB.Prevents accidental coupling to dev/prod DB config and mirrors the backend test fixture pattern.
-runner = CliRunner() +runner = CliRunner(env={"LANGFLOW_DATABASE_URL": "sqlite:///:memory:"})
57-70: Optional: make stderr available explicitly for richer assertions.If you need to inspect stderr separately (color, tracebacks), call
runner.invoke(..., mix_stderr=False)in each invoke and then useresult.stderr. Not required if usingresult.output.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lfx/src/lfx/custom/validate.py(2 hunks)src/lfx/tests/unit/cli/test_run_starter_projects.py(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-21T14:16:14.125Z
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.125Z
Learning: Applies to src/backend/tests/**/*.py : Test flows using predefined JSON data and utility functions such as 'create_flow', 'build_flow', 'get_build_events', and 'consume_and_assert_stream' in backend Python tests.
Applied to files:
src/lfx/tests/unit/cli/test_run_starter_projects.py
🧬 Code graph analysis (2)
src/lfx/tests/unit/cli/test_run_starter_projects.py (1)
src/backend/tests/conftest.py (1)
runner(437-439)
src/lfx/src/lfx/custom/validate.py (1)
src/backend/base/langflow/interface/importing/utils.py (1)
import_module(7-32)
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (46.49%) 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 #9865 +/- ##
=======================================
Coverage 21.47% 21.47%
=======================================
Files 1074 1074
Lines 39650 39650
Branches 5418 5418
=======================================
+ Hits 8513 8516 +3
+ Misses 30993 30990 -3
Partials 144 144
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…Typer's combined output
|
| "asyncer>=0.0.8", | ||
| "structlog", | ||
| "loguru>=0.7.3", | ||
| "langchain>=0.3.23", |
There was a problem hiding this comment.
is this safe?
…dds tests (#9865) Co-authored-by: Edwin Jose <edwin.jose@datastax.com>



Improve error handling in the
prepare_global_scopefunction to provide clearer error messages. Add comprehensive tests to ensure all starter project templates can be loaded without import errors. These tests validate the existence of starter projects and check for proper JSON formatting.Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores