-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat: add option to skip message persistence in Component #8350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 WalkthroughThis update introduces database availability checks into the Changes
Sequence Diagram(s)sequenceDiagram
participant Component
participant DatabaseService
Component->>DatabaseService: get_db_service().database_available
DatabaseService-->>Component: Return True if "message" table exists, else False
Component->>Component: _should_skip_message(message)
alt Database not available
Component-->>Component: Return True (skip message)
else Database available
Component-->>Component: Continue normal processing
end
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/backend/base/langflow/services/database/service.py (2)
73-73: Consider state refresh mechanisms beyond migrations.The initialization to
Falseis appropriately conservative. However, consider implementing mechanisms to refresh this state when database connectivity changes outside of the migration process.
75-84: Consider more comprehensive database health checks.The implementation correctly checks table existence, but using only the "message" table as a database availability indicator may be insufficient. Consider:
- Comprehensive health check: Check for multiple critical tables or perform a simple query
- Error handling: Add exception handling for database connectivity issues
- Efficiency: Consider caching the connection or using the existing session
Example improvement:
async def _is_database_available(self) -> bool: - async with self.with_session() as session, session.bind.connect() as conn: - # Use run_sync to inspect the connection - def check_tables(conn): - inspector = inspect(conn) - return "message" in inspector.get_table_names() - - self._database_available = await conn.run_sync(check_tables) + try: + async with self.with_session() as session, session.bind.connect() as conn: + def check_tables(conn): + inspector = inspect(conn) + required_tables = ["message", "user", "flow"] + return all(table in inspector.get_table_names() for table in required_tables) + + self._database_available = await conn.run_sync(check_tables) + except Exception: + self._database_available = False return self._database_availablesrc/backend/tests/unit/components/agents/test_agent_component.py (1)
155-189: LGTM: Robust Anthropic model testing with proper error handling.The test provides comprehensive coverage of Anthropic models with excellent error handling and detailed failure reporting. The try/catch pattern appropriately handles potential API failures.
Consider reducing code duplication between test classes.
The test methods in
TestAgentComponentWithoutClientare nearly identical to those inTestAgentComponentWithClient. Consider extracting common test logic into a shared base method or mixin to improve maintainability.class AgentTestMixin: async def _test_agent_with_calculator(self, api_key_env_var: str, llm_type: str): # Common test logic here pass async def _test_agent_with_all_models(self, models: list, api_key_env_var: str, llm_type: str): # Common test logic here pass
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/backend/base/langflow/custom/custom_component/component.py(3 hunks)src/backend/base/langflow/services/database/service.py(5 hunks)src/backend/tests/conftest.py(1 hunks)src/backend/tests/unit/components/agents/test_agent_component.py(2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
`src/backend/**/*.py`: Run make format_backend to format Python code early and often Run make lint to check for linting issues in backend Python code
src/backend/**/*.py: Run make format_backend to format Python code early and often
Run make lint to check for linting issues in backend Python code
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/conftest.pysrc/backend/base/langflow/custom/custom_component/component.pysrc/backend/base/langflow/services/database/service.pysrc/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/tests/**/*.py`: Unit tests for backend code should be located in 's...
src/backend/tests/**/*.py: Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests, as defined in 'src/backend/tests/conftest.py'.
Skip client creation in tests by marking them with '@pytest.mark.noclient' when the 'client' fixture is not needed.
Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/conftest.pysrc/backend/tests/unit/components/agents/test_agent_component.py
`{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/...
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}: Each test should have a clear docstring explaining its purpose.
Complex test setups should be commented, and mock usage should be documented within the test code.
Expected behaviors should be explicitly stated in test docstrings or comments.
Create comprehensive unit tests for all new components.
Test both sync and async code paths in components.
Mock external dependencies appropriately in tests.
Test error handling and edge cases in components.
Validate input/output behavior in tests.
Test component initialization and configuration.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/conftest.pysrc/backend/tests/unit/components/agents/test_agent_component.py
`{src/backend/tests/**/*.py,tests/**/*.py}`: Use '@pytest.mark.asyncio' for asyn...
{src/backend/tests/**/*.py,tests/**/*.py}: Use '@pytest.mark.asyncio' for async test functions.
Test queue operations in async tests using 'asyncio.Queue' and non-blocking put/get methods.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests.
Be aware of ContextVar propagation in async tests and test both direct event loop execution and 'asyncio.to_thread' scenarios.
Each test should ensure proper resource cleanup, especially in async fixtures using 'try/finally' and cleanup methods.
Test that operations respect timeout constraints and assert elapsed time is within tolerance.
Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Use 'MockLanguageModel' for testing language model components without external API calls.
Use 'anyio' and 'aiofiles' for async file operations in tests.
Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Test component configuration updates by asserting changes in build config dictionaries.
Test real-time event streaming endpoints by consuming NDJSON event streams and validating event structure.
Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Test webhook endpoints by posting payloads and asserting correct processing and status codes.
Test error handling by monkeypatching internal functions to raise exceptions and asserting correct error responses.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/conftest.pysrc/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/**/*component*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/*component*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/custom/custom_component/component.pysrc/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/tests/unit/components/**/*.py`: Mirror the component directory stru...
src/backend/tests/unit/components/**/*.py: Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping in tests for backward compatibility version testing
Create comprehensive unit tests for all new components
Use the client fixture from conftest.py for FastAPI API endpoint tests
Test authenticated FastAPI endpoints using logged_in_headers in tests
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/tests/unit/**/*.py`: Use in-memory SQLite for database tests Test c...
src/backend/tests/unit/**/*.py: Use in-memory SQLite for database tests
Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/**/components/**/*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/components/**/*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test component configuration updates by asserting changes in build config dictionaries.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: After backend restart, old components will show 'Updates Available' in the UI
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
src/backend/tests/conftest.py (10)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use 'anyio' and 'aiofiles' for async file operations in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Be aware of ContextVar propagation in async tests and test both direct event loop execution and 'asyncio.to_thread' scenarios.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Mock external dependencies appropriately in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test error handling by monkeypatching internal functions to raise exceptions and asserting correct error responses.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Use the 'client' fixture (an async httpx.AsyncClient) for API tests, as defined in 'src/backend/tests/conftest.py'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use '@pytest.mark.asyncio' for async test functions.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use the client fixture from conftest.py for FastAPI API endpoint tests
src/backend/base/langflow/custom/custom_component/component.py (5)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/__init__.py : Update __init__.py with alphabetical imports when adding new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Implement async component methods using async def and await for asynchronous operations
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/services/database/models/**/*.py : Place database models in src/backend/base/langflow/services/database/models/ and its subdirectories
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
src/backend/tests/unit/components/agents/test_agent_component.py (15)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test component configuration updates by asserting changes in build config dictionaries.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test both sync and async code paths in components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use the client fixture from conftest.py for FastAPI API endpoint tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test component initialization and configuration.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Test authenticated FastAPI endpoints using logged_in_headers in tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
🧬 Code Graph Analysis (2)
src/backend/base/langflow/custom/custom_component/component.py (4)
src/backend/base/langflow/services/deps.py (1)
get_db_service(133-142)src/backend/base/langflow/schema/message.py (2)
Message(38-288)ErrorMessage(381-467)src/backend/base/langflow/graph/utils.py (1)
has_chat_output(209-212)src/backend/base/langflow/graph/graph/base.py (1)
get_vertex_neighbors(1790-1808)
src/backend/tests/unit/components/agents/test_agent_component.py (4)
src/backend/tests/base.py (1)
ComponentTestBaseWithoutClient(163-164)src/backend/base/langflow/components/tools/calculator.py (1)
CalculatorToolComponent(15-103)src/backend/base/langflow/components/agents/agent.py (1)
message_response(69-115)src/backend/base/langflow/base/agents/agent.py (1)
message_response(81-87)
🔇 Additional comments (12)
src/backend/base/langflow/services/database/service.py (4)
42-42: LGTM: Explicit initialization improves clarity.The explicit initialization of
enginetoNoneprovides better defensive programming, ensuring the attribute always exists even if engine creation fails.
86-88: LGTM: Clean property implementation.The read-only property correctly encapsulates the private
_database_availableattribute following standard Python patterns.
502-504: LGTM: Improved error handling in teardown.The null check prevents errors when disposing an already-disposed engine, and resetting to
Noneensures clean state for potential reinitialization.
394-394: Database availability integration confirmed for componentsVerified that custom components correctly use the refreshed state after migrations:
src/backend/base/langflow/custom/custom_component/component.py
•_is_database_available()returnsget_db_service().database_available
•_should_skip_message()uses this method to gate message handlingNo further changes required.
src/backend/tests/conftest.py (1)
77-80: LGTM: Appropriate test isolation for database functionality.The additional blocking rules for Alembic migration internals and dotenv functions are well-justified given the new database availability checks and migration handling. These rules help isolate tests from file system operations during database migrations.
src/backend/base/langflow/custom/custom_component/component.py (4)
35-35: LGTM: Clean service dependency import.The import follows the established dependency injection pattern and is correctly placed for use in the database availability check.
163-163: LGTM: Proper attribute initialization.The database availability attribute is correctly typed and follows the established pattern for private attributes in the Component class.
1341-1343: LGTM: Clean delegation pattern.The method properly delegates database availability checking to the service layer and follows the established private method conventions.
1352-1352: LGTM: Correct integration of database availability check.The addition of the database availability condition properly ensures message processing is skipped when the database is unavailable, aligning with the PR's goal of making components responsive to database state.
src/backend/tests/unit/components/agents/test_agent_component.py (3)
23-23: LGTM: Clear class rename following established patterns.The rename to
TestAgentComponentWithoutClientproperly follows the base class pattern and clearly distinguishes the test context from the client-based tests.
104-126: LGTM: Well-structured agent integration test.The test properly uses pytest markers for external API testing, follows established patterns for component testing, and validates the core agent-calculator integration functionality.
128-153: LGTM: Comprehensive model compatibility testing.The test thoroughly validates agent functionality across all OpenAI models with proper test isolation, error collection, and detailed failure reporting.
2f5c623 to
75ce509
Compare
| and not self.is_connected_to_chat_output() | ||
| and not isinstance(message, ErrorMessage) | ||
| ) | ||
| ) or not self._is_database_available() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not having the database available necessarily mean the message should be skipped? e.g. this would also now skip sending the message to the event manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Not having access to the database means there's no API.
Ideally we would have an interface that could be replaced by some storage using a config
| else: | ||
| self.alembic_log_path = Path(langflow_dir) / alembic_log_file | ||
|
|
||
| self._database_available = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Perhaps this is in a follow up PR)
Do you anticipate adding a new config to indicate "No database", or does not setting DATABASE_URL imply no database? Either way, we'll need some changes in the init here to account for that, especially around the create_ methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier for sure. My solution is a hacky one. Perhaps checking for the var first, then checking for the message table would be better.
I'll try to refactor the settings soon and then we can have settings specifically for the initialization, allowing us to skip steps if we so desire
| logger.debug("Alembic not initialized") | ||
| should_initialize_alembic = True | ||
| await asyncio.to_thread(self._run_migrations, should_initialize_alembic, fix) | ||
| self._database_available = await self._is_database_available() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is checked here rather than in init?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function checks if the message table exists, so in init it would not exist the first time Langflow runs.
…ponent_config parameter in flow build functions for enhanced customization
… and maintainability
…from_data for improved robustness
…with persist_messages options
…inputs for cleaner initialization
| stored_message = await self._store_message(message) | ||
| if self._is_database_available(): | ||
| stored_message = await self._store_message(message) | ||
| self._stored_message_id = stored_message.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is being used anymore
| stored_message.text = complete_message | ||
| stored_message = await self._update_stored_message(stored_message) | ||
| if self._is_database_available(): | ||
| stored_message = await self._update_stored_message(stored_message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mutate the stored_message variable? I assume it does based on the context, but what consequences does that have downstream?
First time looking at this area, so I'm a bit confused to the message assignment -- we've got message, stored_message, complete_message.
The main goal here is to not require a db connection for a flow to run. It does feel a bit hacky (because we are checking for the existence of a table) but it works. The best solution could involve a new config but there are edge cases that would make it not work as well.
Database Enhancements:
_is_database_availablemethod and_database_availableproperty toDatabaseServiceto check if the database is operational by verifying the presence of a "message" table. This ensures components can adapt to database availability dynamically. [1] [2]teardownmethod inDatabaseServiceto safely dispose of the database engine and reset it toNoneduring cleanup.Component Updates:
_is_database_availablemethod inComponentto integrate database availability checks into the_should_skip_messagelogic, ensuring messages are only processed when the database is accessible._database_availableattribute in theComponentclass to store the database state.Testing Improvements:
AgentComponentto validate its behavior with OpenAI and Anthropic models, including scenarios using theCalculatorToolComponent. These tests ensure compatibility and correctness across different models.TestAgentComponenttoTestAgentComponentWithoutClientfor clarity in distinguishing test classes.Miscellaneous:
blockbusterfunction inconftest.pyto include additional modules and functions for blocking