Skip to content

feat(database): add noop mode with config flag and update related tests#9054

Merged
ogabrielluiz merged 10 commits into
mainfrom
add-noop-session
Jul 15, 2025
Merged

feat(database): add noop mode with config flag and update related tests#9054
ogabrielluiz merged 10 commits into
mainfrom
add-noop-session

Conversation

@ogabrielluiz
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz commented Jul 15, 2025

Summary by CodeRabbit

  • New Features
    • Added an option to disable all database operations and use a no-op session via a new configuration setting.
  • Bug Fixes
    • Improved handling of database query results to prevent errors with different return types.
  • Tests
    • Added tests to verify message sending and agent behavior when the database is disabled.
    • Enhanced model coverage and error handling in agent component tests.
    • Introduced new test fixtures to support no-op database mode.

…less sessions

- Added `use_noop_session` fixture to facilitate testing without a database.
- Expanded `TestAgentComponent` with new tests for agent responses using the Calculator tool and validation across all OpenAI and Anthropic models.
- Updated `test_component.py` to include tests for message sending without a database, ensuring proper event handling and message integrity.
- Refactored existing tests for clarity and consistency.
…rdown_superuser functions

- Updated user retrieval in both functions to handle different result types from the database query, ensuring robustness against unexpected return values.
- Added checks for `first()` method and list type to improve error handling and maintainability.
- Introduced `use_noop_database` configuration option to disable all database operations, controlled by the `LANGFLOW_USE_NOOP_DATABASE` environment variable.
- Updated the `use_noop_session` fixture to reflect the new environment variable for testing without a database.
- Added NoopSession class to provide a no-operation database session, allowing for testing and operation without a real database connection.
- Updated DatabaseService to utilize NoopSession when the `use_noop_database` setting is enabled, ensuring all database operations are disabled in this mode.
- Enhanced error handling and logging for session management, improving robustness in scenarios where the database is not in use.
- Changed import path for NoopSession from `langflow.services.database.service` to `langflow.services.database.session` in both `test_agent_component.py` and `test_component.py`.
- This refactor improves code organization and aligns with recent changes in the project structure.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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.

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

Walkthrough

A no-operation (noop) database mode was introduced, controlled by a new configuration flag. When enabled, the system uses a stub session class that bypasses all database operations. The database service, settings, and utility functions were updated to support this mode. Tests and fixtures were added and updated to verify behavior with and without a real database.

Changes

Files / Areas Change Summary
src/backend/base/langflow/services/database/service.py Modified session context manager to yield a NoopSession when noop mode is enabled.
src/backend/base/langflow/services/database/session.py Introduced NoopSession class with async no-op methods and context management.
src/backend/base/langflow/services/settings/base.py Added use_noop_database boolean config flag to settings.
src/backend/base/langflow/services/utils.py Updated user query logic to handle different return types from session execution.
src/backend/tests/conftest.py Added use_noop_session fixture and extended blocking allowances for testing.
src/backend/tests/unit/components/agents/test_agent_component.py Added/renamed tests for agent components, with coverage for multiple models and session mocking.
src/backend/tests/unit/custom/custom_component/test_component.py Added async tests for message sending with mocked NoopSession and event manager interactions.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Settings
    participant DatabaseService
    participant NoopSession
    participant AsyncSession

    App->>Settings: Check use_noop_database flag
    App->>DatabaseService: Request session (with_session)
    alt use_noop_database is True
        DatabaseService->>NoopSession: Create NoopSession
        DatabaseService-->>App: Yield NoopSession
    else
        DatabaseService->>AsyncSession: Create AsyncSession
        DatabaseService-->>App: Yield AsyncSession
    end
    App->>DatabaseService: Perform DB operations (add, commit, etc.)
    Note right of NoopSession: All methods are no-ops
Loading

Suggested labels

enhancement, size:L, refactor, lgtm

Suggested reviewers

  • jordanrfrazier
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-noop-session

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 15, 2025
@coderabbitai coderabbitai Bot changed the title @coderabbitai feat(database): add noop mode with config flag and update related tests Jul 15, 2025
@github-actions github-actions Bot added the enhancement New feature or request label Jul 15, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/backend/base/langflow/services/database/session.py (1)

1-53: NoopSession implementation needs interface consistency improvements.

The implementation provides good async stubs for database operations, but there are interface compatibility concerns:

  1. exec() method inconsistency: Returns an empty list, but real sessions return result objects with methods like .first(). This forces defensive programming in other parts of the codebase.

  2. Missing result object interface: Consider implementing a NoopResult class that mimics the real session result interface.

Consider implementing a more compatible interface:

+class NoopResult:
+    def first(self):
+        return None
+    
+    def all(self):
+        return []
+    
+    def __iter__(self):
+        return iter([])

 class NoopSession:
     # ... existing code ...
     
     async def exec(self, *args, **kwargs):  # noqa: ARG002
-        return []
+        return NoopResult()

This would eliminate the need for defensive programming in utils.py and provide better interface consistency.

🧹 Nitpick comments (1)
src/backend/tests/unit/custom/custom_component/test_component.py (1)

113-133: Well-structured test for NoopSession integration.

The test correctly verifies Component's send_message behavior with NoopSession, properly mocking async methods and asserting expected calls. Consider removing the unused monkeypatch parameter if it's not needed for consistency with other tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7858309 and e4c8ae6.

📒 Files selected for processing (7)
  • src/backend/base/langflow/services/database/service.py (2 hunks)
  • src/backend/base/langflow/services/database/session.py (1 hunks)
  • src/backend/base/langflow/services/settings/base.py (1 hunks)
  • src/backend/base/langflow/services/utils.py (2 hunks)
  • src/backend/tests/conftest.py (2 hunks)
  • src/backend/tests/unit/components/agents/test_agent_component.py (5 hunks)
  • src/backend/tests/unit/custom/custom_component/test_component.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
src/backend/**/*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/backend_development.mdc
src/backend/tests/**/*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/testing.mdc
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/testing.mdc
{src/backend/tests/**/*.py,tests/**/*.py}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/testing.mdc
src/backend/tests/unit/**/*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/backend_development.mdc
src/backend/**/*component*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/icons.mdc
src/backend/tests/unit/components/**/*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/backend_development.mdc
src/backend/**/components/**/*.py

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/icons.mdc
🧠 Learnings (3)
src/backend/tests/conftest.py (11)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.464Z
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.849Z
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.849Z
Learning: Applies to src/backend/tests/**/*.py : Skip client creation in tests by marking them with '@pytest.mark.noclient' when the 'client' fixture is not needed.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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.849Z
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.849Z
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.849Z
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/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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.
src/backend/tests/unit/custom/custom_component/test_component.py (18)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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.464Z
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/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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.849Z
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/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use 'MockLanguageModel' for testing language model components without external API calls.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
src/backend/tests/unit/components/agents/test_agent_component.py (21)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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.464Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.464Z
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.849Z
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/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use 'MockLanguageModel' for testing language model components without external API calls.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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.849Z
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.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.464Z
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.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
🧬 Code Graph Analysis (1)
src/backend/tests/unit/components/agents/test_agent_component.py (4)
src/backend/base/langflow/services/database/session.py (1)
  • NoopSession (1-52)
src/backend/tests/base.py (2)
  • ComponentTestBaseWithClient (159-160)
  • 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 (83-127)
🔇 Additional comments (15)
src/backend/base/langflow/services/settings/base.py (1)

129-132: Configuration field implementation looks good.

The new use_noop_database setting is properly defined with clear documentation and appropriate defaults. The environment variable mapping follows the established pattern.

src/backend/base/langflow/services/database/service.py (2)

30-30: Good import addition.

The import of NoopSession is properly placed and follows the existing import structure.


185-200: Conditional session logic is well implemented.

The implementation correctly:

  • Checks the configuration flag to determine session type
  • Provides helpful warning when noop mode is enabled
  • Maintains proper error handling for real database sessions
  • Preserves the async context manager interface

The conditional logic ensures backward compatibility while adding the new no-op functionality.

src/backend/tests/conftest.py (2)

79-82: Appropriate blockbuster extensions for database operations.

The additional blocking permissions for Alembic migration files and dotenv operations are reasonable and necessary for database setup during tests.


373-381: Well-implemented test fixture for noop mode.

The fixture properly:

  • Sets the environment variable to enable noop database mode
  • Uses monkeypatch for proper test isolation
  • Includes cleanup with monkeypatch.undo()
  • Follows pytest fixture conventions

This will enable comprehensive testing of the noop database functionality.

src/backend/base/langflow/services/utils.py (1)

123-129: Consistent defensive programming pattern.

The same defensive pattern is applied here as in the get_or_create_super_user function, which maintains consistency in handling different session return types.

src/backend/tests/unit/custom/custom_component/test_component.py (4)

2-2: LGTM! Imports are appropriate for the new tests.

The added imports for AsyncMock, patch, Component, Message, and NoopSession are correctly used in the new test functions.

Also applies to: 8-8, 11-12


31-31: Good practice: Added reason to xfail marker.

Adding a reason to the xfail marker improves test documentation and maintainability.


84-85: Appropriate linting suppressions for unused arguments.

The # noqa: ARG002 comments correctly suppress warnings for unused arguments that are required by the method signature but not used in these test implementations.

Also applies to: 101-102


135-163: Good test coverage for AgentComponent with NoopSession.

The test correctly verifies AgentComponent's send_message behavior, following the same pattern as the Component test. This ensures consistent behavior across different component types when using NoopSession.

src/backend/tests/unit/components/agents/test_agent_component.py (5)

3-3: LGTM! Imports support NoopSession testing.

The added imports for AsyncMock, patch, and NoopSession are appropriately used in the new test methods.

Also applies to: 18-18


26-26: Class rename follows testing conventions.

The rename to TestAgentComponentWithoutClient correctly aligns with the component testing pattern, inheriting from ComponentTestBaseWithoutClient as per the coding guidelines.


134-165: Verify agent_llm parameter value.

The test sets agent_llm=None while llm_type="OpenAI". This appears inconsistent with other tests where agent_llm="OpenAI" is used for OpenAI models.

Consider aligning with the pattern used in other tests:

-                    agent_llm=None,
+                    agent_llm="OpenAI",

166-201: Well-structured comprehensive test for Anthropic models.

The test excellently covers all Anthropic models with proper error handling and detailed failure reporting. The use of a dictionary to track failures per model with specific error messages is a great improvement over simple assertions.


216-216: Good improvements to error tracking and consistency.

The changes improve the tests by:

  • Using dictionaries for detailed failure tracking with specific error messages
  • Adding exception handling to prevent cascading failures
  • Making the code more consistent between test classes
  • Properly setting agent_llm="OpenAI" instead of None

Also applies to: 241-259

Comment on lines +32 to +38
result = await session.exec(stmt)
if hasattr(result, "first"):
user = result.first()
elif isinstance(result, list):
user = result[0] if result else None
else:
user = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Defensive programming for session compatibility.

The updated logic handles different possible return types from session.exec(), which suggests the NoopSession and real sessions might have different return interfaces. While this approach is robust, it indicates a potential inconsistency in the session interface.

Consider ensuring NoopSession.exec() returns a result object that behaves consistently with real sessions (i.e., has a .first() method) to maintain interface compatibility and avoid the need for this defensive code.

🤖 Prompt for AI Agents
In src/backend/base/langflow/services/utils.py around lines 32 to 38, the code
defensively checks the type of the result from session.exec() due to differing
interfaces between NoopSession and real sessions. To fix this, modify
NoopSession.exec() so it returns an object with a .first() method consistent
with real session results. This will unify the interface and allow removing the
type checks and conditional logic in this code.

Comment on lines +104 to +133
@pytest.mark.api_key_required
@pytest.mark.no_blockbuster
async def test_agent_component_with_calculator(self):
# Now you can access the environment variables
api_key = os.getenv("OPENAI_API_KEY")
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
input_value = "What is 2 + 2?"

temperature = 0.1

# Initialize the AgentComponent with mocked inputs
agent = AgentComponent(
tools=tools,
input_value=input_value,
api_key=api_key,
model_name="gpt-4.1-nano",
llm_type="OpenAI",
temperature=temperature,
_session_id=str(uuid4()),
)

with (
patch.object(NoopSession, "add", new_callable=AsyncMock) as mock_add,
patch.object(NoopSession, "commit", new_callable=AsyncMock) as mock_commit,
):
response = await agent.message_response()
assert mock_add.called
assert mock_commit.called
assert "4" in response.data.get("text")

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid OpenAI model name.

The model name "gpt-4.1-nano" is not a valid OpenAI model. This will likely cause the test to fail when run with actual API credentials.

Replace with a valid model name from the available OpenAI models:

-            model_name="gpt-4.1-nano",
+            model_name="gpt-4o-mini",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@pytest.mark.api_key_required
@pytest.mark.no_blockbuster
async def test_agent_component_with_calculator(self):
# Now you can access the environment variables
api_key = os.getenv("OPENAI_API_KEY")
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
input_value = "What is 2 + 2?"
temperature = 0.1
# Initialize the AgentComponent with mocked inputs
agent = AgentComponent(
tools=tools,
input_value=input_value,
api_key=api_key,
model_name="gpt-4.1-nano",
llm_type="OpenAI",
temperature=temperature,
_session_id=str(uuid4()),
)
with (
patch.object(NoopSession, "add", new_callable=AsyncMock) as mock_add,
patch.object(NoopSession, "commit", new_callable=AsyncMock) as mock_commit,
):
response = await agent.message_response()
assert mock_add.called
assert mock_commit.called
assert "4" in response.data.get("text")
@pytest.mark.api_key_required
@pytest.mark.no_blockbuster
async def test_agent_component_with_calculator(self):
# Now you can access the environment variables
api_key = os.getenv("OPENAI_API_KEY")
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
input_value = "What is 2 + 2?"
temperature = 0.1
# Initialize the AgentComponent with mocked inputs
agent = AgentComponent(
tools=tools,
input_value=input_value,
api_key=api_key,
- model_name="gpt-4.1-nano",
+ model_name="gpt-4o-mini",
llm_type="OpenAI",
temperature=temperature,
_session_id=str(uuid4()),
)
with (
patch.object(NoopSession, "add", new_callable=AsyncMock) as mock_add,
patch.object(NoopSession, "commit", new_callable=AsyncMock) as mock_commit,
):
response = await agent.message_response()
assert mock_add.called
assert mock_commit.called
assert "4" in response.data.get("text")
🤖 Prompt for AI Agents
In src/backend/tests/unit/components/agents/test_agent_component.py between
lines 104 and 133, the test uses an invalid OpenAI model name "gpt-4.1-nano"
which will cause failures. Replace "gpt-4.1-nano" with a valid OpenAI model name
such as "gpt-4" or "gpt-3.5-turbo" to ensure the test runs correctly with real
API credentials.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

@ogabrielluiz Thank you for the correction! I need to verify the current status of the GPT-4.1-nano model to provide accurate information.


🌐 Web query:

OpenAI GPT-4.1-nano model availability and documentation 2024 2025

💡 Result:

OpenAI introduced the GPT-4.1 series on April 14, 2025, comprising three models: GPT-4.1, GPT-4.1 mini, and GPT-4.1 nano. These models are designed to enhance coding capabilities, instruction following, and long-context comprehension, supporting up to 1 million tokens. (openai.com)

Availability:

  • API Access: All three models are available exclusively through OpenAI's API. (openai.com)

  • ChatGPT Integration: GPT-4.1 has been integrated into ChatGPT for Plus, Pro, and Team users since May 14, 2025. (help.openai.com)

  • Third-Party Platforms: The models are also accessible via platforms like GitHub Models and Azure OpenAI Service. (github.blog, ai.azure.com)

Documentation:

Comprehensive documentation for the GPT-4.1 series, including details on model performance, pricing, and usage guidelines, is available on OpenAI's official website. (openai.com)

For the most current information and updates, refer to OpenAI's official channels and documentation.

Citations:


🌐 Web query:

OpenAI models list GPT-4.1-nano current available models API 2025

💡 Result:

OpenAI has introduced a new family of AI models, including GPT-4.1, GPT-4.1 mini, and GPT-4.1 nano, all available exclusively through OpenAI's API. These models offer significant advancements in coding capabilities, long-context comprehension, and instruction following. Notably, GPT-4.1 supports context windows of up to 1 million tokens, enhancing its ability to process and understand extensive datasets. Additionally, these models operate at a reduced cost compared to previous versions, such as GPT-4.5. (reuters.com)

The GPT-4.1 family is designed to be more effective for powering AI agents, with improved performance in practical applications. OpenAI has announced plans to discontinue the GPT-4.5 preview in the API by July 2025, as the new models offer improved or similar performance. (reuters.com)

These models are currently accessible via OpenAI's API, providing developers with enhanced tools for building AI applications.

OpenAI's GPT-4.1 Models: Enhancements and Availability:

Citations:


@ogabrielluiz You're absolutely right! I apologize for the incorrect assessment. Based on the current documentation, GPT-4.1-nano is indeed a valid OpenAI model.

According to the latest information from OpenAI's official sources:

  • GPT-4.1-nano is part of the GPT-4.1 series introduced by OpenAI on April 14, 2025
  • The GPT-4.1 family includes three models: GPT-4.1, GPT-4.1 mini, and GPT-4.1 nano
  • All models are available exclusively through OpenAI's API
  • They offer enhanced coding capabilities, instruction following, and long-context comprehension with support for up to 1 million tokens
  • They're accessible via OpenAI's API, GitHub Models, and Azure OpenAI Service

The test code using model_name="gpt-4.1-nano" is correct and should work properly with valid API credentials. Thank you for the correction and for providing the documentation link!


✏️ Learnings added
Learnt from: ogabrielluiz
PR: langflow-ai/langflow#9054
File: src/backend/tests/unit/components/agents/test_agent_component.py:104-133
Timestamp: 2025-07-15T14:37:19.155Z
Learning: The GPT-4.1 series models (GPT-4.1, GPT-4.1 mini, and GPT-4.1 nano) are valid OpenAI models introduced on April 14, 2025, available exclusively through OpenAI's API with enhanced coding capabilities and 1 million token context support.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
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.849Z
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.464Z
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/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.464Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
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.849Z
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/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
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.849Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.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.464Z
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.849Z
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.

- Added an internal _NoopResult class to the NoopSession, providing methods `first()`, `all()`, and `one_or_none()` for better handling of no-operation results.
- This enhancement improves the usability of NoopSession in testing scenarios by mimicking expected database query behaviors.
- Changed the log level from warning to info for the NOOP database session message in the DatabaseService class.
- This adjustment enhances clarity in logging, indicating that all DB operations are disabled without implying an error condition.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 15, 2025
- Reformatted the docstring for the custom_component_update function to enhance readability by breaking long lines into multiple lines.
- This change improves documentation clarity, making it easier for developers to understand the function's purpose and behavior.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 15, 2025
@ogabrielluiz
Copy link
Copy Markdown
Contributor Author

@coderabbitai review again, please

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 15, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@ogabrielluiz I'll review this PR that introduces the noop database mode. Let me examine the implementation details first.


🏁 Script executed:

#!/bin/bash
# Examine the key implementation files to understand the code structure better
echo "=== NoopSession implementation ==="
cat src/backend/base/langflow/services/database/session.py

echo -e "\n=== Database service changes ==="
cat src/backend/base/langflow/services/database/service.py

echo -e "\n=== Settings configuration ==="
cat src/backend/base/langflow/services/settings/base.py | grep -A 5 -B 5 "use_noop_database"

echo -e "\n=== Utils changes ==="
cat src/backend/base/langflow/services/utils.py | grep -A 20 -B 5 "result.*first"

Length of output: 25132


🏁 Script executed:

#!/bin/bash
# Let's examine the test implementations to understand how this is being tested
echo "=== Test fixture for noop session ==="
cat src/backend/tests/conftest.py | grep -A 20 -B 5 "use_noop_session"

echo -e "\n=== Agent component tests ==="
cat src/backend/tests/unit/components/agents/test_agent_component.py | grep -A 30 -B 5 "NoopSession\|noop"

echo -e "\n=== Custom component tests ==="
cat src/backend/tests/unit/custom/custom_component/test_component.py | grep -A 30 -B 5 "NoopSession\|noop"

Length of output: 7378


Excellent work on implementing the noop database mode! This is a well-structured enhancement that provides clean separation between database-enabled and database-disabled modes. Here's my comprehensive review:

🎯 Overall Assessment

This implementation is well-designed and thoughtfully executed. The noop database mode provides valuable functionality for testing, demos, and scenarios where database operations need to be disabled.

Strengths

1. Comprehensive NoopSession Implementation

class NoopSession:
    # Well-structured with nested classes for proper interface compliance
    class NoopBind:
        class NoopConnect:
            async def __aenter__(self):
                return self
            async def __aexit__(self, exc_type, exc, tb):
                pass

The NoopSession class provides a complete async interface that matches the expected SQLAlchemy session behavior.

2. Clean Configuration Management

use_noop_database: bool = False
"""If True, disables all database operations and uses a no-op session.
Controlled by LANGFLOW_USE_NOOP_DATABASE env variable."""

Well-documented configuration with clear environment variable control.

3. Proper Context Management

@asynccontextmanager
async def with_session(self):
    if self.settings_service.settings.use_noop_database:
        logger.info("Running with NOOP database session. All DB operations are disabled.")
        yield NoopSession()
    else:
        async with AsyncSession(self.engine, expire_on_commit=False) as session:
            # ... existing logic

The conditional logic is clean and includes helpful logging.

4. Robust Result Handling

class _NoopResult:
    def first(self):
        return None
    def all(self):
        return []
    def one_or_none(self):
        return None

The _NoopResult class handles various query result methods appropriately.

🔧 Minor Suggestions for Improvement

1. Enhanced Error Handling in NoopSession

Consider adding optional validation to catch potential issues during development:

async def execute(self, *args, **kwargs):
    if self._debug_mode:  # Optional debug flag
        logger.debug(f"NoopSession.execute called with: {args}, {kwargs}")
    return None

2. More Comprehensive _NoopResult Methods

The _NoopResult class could benefit from additional methods that might be called:

class _NoopResult:
    def first(self):
        return None
    def all(self):
        return []
    def one_or_none(self):
        return None
    def scalar(self):
        return None
    def scalars(self):
        return []
    def fetchone(self):
        return None
    def fetchall(self):
        return []

3. Consider Adding Metrics/Monitoring

For production use, you might want to track noop operations:

class NoopSession:
    def __init__(self):
        self._operation_count = 0
    
    async def add(self, *args, **kwargs):
        self._operation_count += 1
        logger.debug(f"NoopSession: {self._operation_count} operations bypassed")

🧪 Testing Quality

The test coverage is excellent:

@pytest.mark.usefixtures("use_noop_session")
@pytest.mark.asyncio
async def test_send_message_without_database(monkeypatch):
    with (
        patch.object(NoopSession, "add", new_callable=AsyncMock) as mock_add,
        patch.object(NoopSession, "commit", new_callable=AsyncMock) as mock_commit,
    ):
        # ... test logic
        assert mock_add.called
        assert mock_commit.called

The mocking strategy properly verifies that database operations are called even in noop mode.

🔍 Edge Cases Considered

1. Utils Result Handling

The updates to handle different return types from session.exec() are well-implemented:

result = await session.exec(stmt)
if hasattr(result, 'first'):
    user = result.first()
elif isinstance(result, list):
    user = result[0] if result else None
else:
    user = None

This properly handles both real SQLAlchemy results and noop results.

2. Session Context Management

The async context management is properly implemented to ensure compatibility with existing code.

🚀 Integration Assessment

The implementation integrates seamlessly with the existing codebase:

  • ✅ Maintains backward compatibility
  • ✅ Follows existing patterns and conventions
  • ✅ Proper logging and error handling
  • ✅ Clean separation of concerns

📋 Final Recommendation

This PR is ready for merge. The implementation is solid, well-tested, and provides valuable functionality for testing and development scenarios. The noop database mode will be particularly useful for:

  • Testing environments where database operations should be bypassed
  • Demo scenarios where persistence isn't required
  • Development workflows where database setup is complex
  • CI/CD pipelines where database operations need to be disabled

The code quality is high, the test coverage is comprehensive, and the feature is well-documented. Great work! 🎉


🧠 Learnings used
Learnt from: edwinjosechittilappilly
PR: langflow-ai/langflow#8504
File: src/backend/base/langflow/initial_setup/starter_projects/Image Sentiment Analysis.json:391-393
Timestamp: 2025-06-12T15:25:01.072Z
Learning: The repository owner prefers CodeRabbit not to review or comment on JSON files because they are autogenerated.

Comment thread src/backend/base/langflow/services/database/service.py Outdated
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Jul 15, 2025
- Introduced documentation for the new LANGFLOW_USE_NOOP_DATABASE environment variable, which allows users to enable a no-op database mode, avoiding database connections and operations.
- This addition enhances the clarity of configuration options available for Langflow, aiding users in understanding how to run flows without a database.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 15, 2025
- Removed the logging statement from the DatabaseService class and added it to the `set_use_noop_database` field validator in the Settings class.
- This change centralizes the logging for the NOOP database session, improving code organization and ensuring that the message is logged whenever the setting is applied.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 15, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 15, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@ogabrielluiz ogabrielluiz enabled auto-merge July 15, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants