fix: apikey lock issue and add option to disable tracking#8361
Conversation
## Walkthrough
A new environment variable, `LANGFLOW_DISABLE_TRACK_APIKEY_USAGE`, has been introduced and documented. In the API key checking logic, the update of API key usage metrics is now gated by this variable and is performed synchronously rather than as a background task. No public APIs or signatures were changed.
## Changes
| File(s) | Change Summary |
|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| docs/docs/Configuration/environment-variables.md | Documented the new `LANGFLOW_DISABLE_TRACK_APIKEY_USAGE` environment variable and its behavior. |
| src/backend/base/langflow/services/settings/base.py | Added `disable_track_apikey_usage` boolean field to `Settings` class with default `False`. |
| src/backend/base/langflow/services/database/models/api_key/crud.py | Removed async task usage; added conditional synchronous awaited update of API key usage metrics based on setting. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Client
participant API
participant Database
Client->>API: Send request with API key
API->>API: Check LANGFLOW_DISABLE_TRACK_APIKEY_USAGE
alt Tracking enabled
API->>Database: Update API key usage metrics (awaited)
else Tracking disabled
API-->>Database: Skip usage metrics update
end
API-->>Client: Respond to request |
|
Build successful! ✅ |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/docs/Configuration/environment-variables.md(1 hunks)src/backend/base/langflow/services/database/models/api_key/crud.py(2 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
src/backend/base/langflow/services/database/models/api_key/crud.py
[convention] 1-1: Missing module docstring
(C0114)
🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/services/database/models/api_key/crud.py
[failure] 1-14: Ruff (I001)
src/backend/base/langflow/services/database/models/api_key/crud.py:1:1: I001 Import block is un-sorted or un-formatted
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/services/database/models/api_key/crud.py
[error] 1-1: Ruff: Import block is un-sorted or un-formatted (I001)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Optimize new Python code in this PR
- GitHub Check: Update Starter Projects
🔇 Additional comments (2)
src/backend/base/langflow/services/database/models/api_key/crud.py (1)
59-60: LGTM! Environment variable logic and synchronous fix are correct.The implementation correctly:
- Checks the environment variable with proper default and case-insensitive comparison
- Fixes the database lock issue by using synchronous
awaitinstead ofasyncio.create_task- Preserves backward compatibility with tracking enabled by default
Note that this change may slightly increase API response times since validation now waits for the database update to complete, but this trade-off resolves the database contention issue under high concurrency.
docs/docs/Configuration/environment-variables.md (1)
194-194: Excellent documentation for the new environment variable.The documentation is clear, accurate, and properly formatted. It correctly describes:
- The variable type and default value
- The specific functionality it controls (
total_usesandlast_used_attracking)- The use case (avoiding database contention under high concurrency)
This aligns perfectly with the code implementation in the crud.py file.
|
Build successful! ✅ |
mendonk
left a comment
There was a problem hiding this comment.
Approving for docs, thank you @italojohnny
|
Build successful! ✅ |
|
Build successful! ✅ |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/base/langflow/services/database/models/api_key/crud.py(2 hunks)src/backend/base/langflow/services/settings/base.py(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/backend/base/langflow/services/settings/base.py
🧰 Additional context used
🪛 Ruff (0.11.9)
src/backend/base/langflow/services/database/models/api_key/crud.py
58-58: Avoid inequality comparisons to True; use if not ...: for false checks
Replace comparison
(E712)
🪛 Pylint (3.3.7)
src/backend/base/langflow/services/database/models/api_key/crud.py
[convention] 58-58: Comparison 'settings_service.settings.disable_track_apikey_usage != True' should be 'settings_service.settings.disable_track_apikey_usage is not True' if checking for the singleton value True, or 'not settings_service.settings.disable_track_apikey_usage' if testing for falsiness
(C0121)
🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/services/database/models/api_key/crud.py
[failure] 58-58: Ruff (E712)
src/backend/base/langflow/services/database/models/api_key/crud.py:58:12: E712 Avoid inequality comparisons to True; use if not ...: for false checks
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/services/database/models/api_key/crud.py
[error] 58-58: Ruff E712: Avoid inequality comparisons to True; use if not ...: for false checks.
🔇 Additional comments (1)
src/backend/base/langflow/services/database/models/api_key/crud.py (1)
12-12: LGTM!The import of
get_settings_serviceis correctly added to support the new conditional tracking functionality.
| settings_service = get_settings_service() | ||
| if settings_service.settings.disable_track_apikey_usage != True: | ||
| await update_total_uses(api_key_object.id) |
There was a problem hiding this comment.
Fix the boolean comparison style to resolve pipeline failure.
The logic correctly implements conditional API key usage tracking, but the boolean comparison violates Python style conventions and is causing pipeline failures.
Apply this diff to fix the style issue:
- if settings_service.settings.disable_track_apikey_usage != True:
+ if not settings_service.settings.disable_track_apikey_usage:Note on performance: The change from async fire-and-forget tasks to synchronous awaited calls addresses the database lock issue but may impact response times since API key validation now waits for usage tracking to complete.
📝 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.
| settings_service = get_settings_service() | |
| if settings_service.settings.disable_track_apikey_usage != True: | |
| await update_total_uses(api_key_object.id) | |
| settings_service = get_settings_service() | |
| if not settings_service.settings.disable_track_apikey_usage: | |
| await update_total_uses(api_key_object.id) |
🧰 Tools
🪛 Ruff (0.11.9)
58-58: Avoid inequality comparisons to True; use if not ...: for false checks
Replace comparison
(E712)
🪛 Pylint (3.3.7)
[convention] 58-58: Comparison 'settings_service.settings.disable_track_apikey_usage != True' should be 'settings_service.settings.disable_track_apikey_usage is not True' if checking for the singleton value True, or 'not settings_service.settings.disable_track_apikey_usage' if testing for falsiness
(C0121)
🪛 GitHub Check: Ruff Style Check (3.13)
[failure] 58-58: Ruff (E712)
src/backend/base/langflow/services/database/models/api_key/crud.py:58:12: E712 Avoid inequality comparisons to True; use if not ...: for false checks
🪛 GitHub Actions: Ruff Style Check
[error] 58-58: Ruff E712: Avoid inequality comparisons to True; use if not ...: for false checks.
🤖 Prompt for AI Agents
In src/backend/base/langflow/services/database/models/api_key/crud.py around
lines 57 to 59, the boolean comparison uses '!= True', which violates Python
style conventions and causes pipeline failures. Replace the condition
'settings_service.settings.disable_track_apikey_usage != True' with 'not
settings_service.settings.disable_track_apikey_usage' to fix the style issue.
Also, ensure that the call to update_total_uses is properly awaited to handle
the database lock issue, accepting the potential impact on response times.
f7cb001 to
58cb1b2
Compare
|
Build successful! ✅ |
* fix(api-key): avoid row-level locks by disabling usage tracking * [autofix.ci] apply automated fixes * chore: move parameter handling to settings service --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361)
…nnections settings page (#8388) * Added mcpinput to the backend * Fixed list selection component to contain descriptions * Added mcp component in the frontend with mock values * Added mcp rendering on Parameter Render Component * Changed input to be more concise and to have dynamic placeholder * Added header search placeholder * Fixed styling to match new input * Removed unused params * Adds AddMcpServerModal's first mock version * Adds Add button on mcp component and list selection component * First pass at mcp api * Add PATCH endpoint * Add DELETE endpoint * fix: Bump version numbers for langflow and langflow-base to 1.4.3 and 0.4.3 respectively * fix: Remove Igor Carvalho from maintainers list in pyproject.toml * fix(agent): reset model list when provider changes Switching the provider in the Agent component sometimes left models from the previous provider visible/selected. We now filter against the new , ensuring only models that belong to the active provider remain. * src/frontend/src/components/core/dropdownComponent/index.tsx – add guard when rebuilding * tests/extended/regression/general-bugs-dropdown-select-not-in-list.spec.ts – expand coverage for “model not in list” edge-cases Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> * fix: Update Pokédex Agent template (#8373) * Implement adding and getting MCP servers, implemented addMcpServerModal * Added sse and stdio ways of adding a server * Added no actions handling * added new mcp type to constants * Added headers to add mcp server modal * Changed mcp component to allow persistent mcp servers * fix input list component gradient * fix add server modal to patch when initial data is present, and to clean variables when switching tabs * changed message on add mcp server * Added required mutations for mcp page * Added mcp servers page * Changed design of page * Fixed delete problems and added delete confirmation * fixed wrong error parsing * changed padding * Made added server be used on mcp component * refactor: remove references to the langflow store (#8354) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361) * Fixed search on sidebar * fixed infinite use effect * Fixed error handling * Fixed tool mode disappearing * fixed key pair button submitting form * Fixed bugs * Added required * Changed message * Disabled other tabs when modifying * Removed tool dropdown if the mcp server is empty * parsed name * fixed data test id not applying * fixed mcp component * Fixed component not working when only stdio command is present * refactored tests * Updated mcp_component to remove old non default keys * Added data-testids * Modified tests to include settings page functionality * [autofix.ci] apply automated fixes * Refactor out the core part of the mcp * [autofix.ci] apply automated fixes * Added placeholders on frontend components for errors * Fixed bugs with mcp component * updated bug * fix: made empty project appear instead of empty flows list when mcp is enabled (#8336) * try to fix * Fix MCP persistence * Update mcp_component.py * Update mcp.py * [autofix.ci] apply automated fixes * fix: Bump version numbers for langflow and langflow-base to 1.4.3 and 0.4.3 respectively * fix: Remove Igor Carvalho from maintainers list in pyproject.toml * fix(agent): reset model list when provider changes Switching the provider in the Agent component sometimes left models from the previous provider visible/selected. We now filter against the new , ensuring only models that belong to the active provider remain. * src/frontend/src/components/core/dropdownComponent/index.tsx – add guard when rebuilding * tests/extended/regression/general-bugs-dropdown-select-not-in-list.spec.ts – expand coverage for “model not in list” edge-cases Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> * refactor: remove references to the langflow store (#8354) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (#8361) * fix: made empty project appear instead of empty flows list when mcp is enabled (#8336) * fix mcp client async problems * fixed mcp sse access * [autofix.ci] apply automated fixes * Made values be maintained when refreshing page * Fixed bugs with tool mode and switching from tool mode to not tool mode * Update mcp_component.py * Update test_mcp_component.py * Don't expose file by name as external endpoint * Update files.py * Update files.py * Add checks for id * Refactor tests * Update test_mcp_component.py * Update test_mcp_component.py * Update test_mcp_component.py * updated tests * re-added placeholder on input for tests to not fail * updated session selector in order for tests to work --------- Co-authored-by: Eric Hare <ericrhare@gmail.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: Mike Fortman <michael.fortman@datastax.com> Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com> Co-authored-by: Deon Sanchez <69873175+deon-sanchez@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
…i#8361) * fix(api-key): avoid row-level locks by disabling usage tracking * [autofix.ci] apply automated fixes * chore: move parameter handling to settings service --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…nnections settings page (langflow-ai#8388) * Added mcpinput to the backend * Fixed list selection component to contain descriptions * Added mcp component in the frontend with mock values * Added mcp rendering on Parameter Render Component * Changed input to be more concise and to have dynamic placeholder * Added header search placeholder * Fixed styling to match new input * Removed unused params * Adds AddMcpServerModal's first mock version * Adds Add button on mcp component and list selection component * First pass at mcp api * Add PATCH endpoint * Add DELETE endpoint * fix: Bump version numbers for langflow and langflow-base to 1.4.3 and 0.4.3 respectively * fix: Remove Igor Carvalho from maintainers list in pyproject.toml * fix(agent): reset model list when provider changes Switching the provider in the Agent component sometimes left models from the previous provider visible/selected. We now filter against the new , ensuring only models that belong to the active provider remain. * src/frontend/src/components/core/dropdownComponent/index.tsx – add guard when rebuilding * tests/extended/regression/general-bugs-dropdown-select-not-in-list.spec.ts – expand coverage for “model not in list” edge-cases Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> * fix: Update Pokédex Agent template (langflow-ai#8373) * Implement adding and getting MCP servers, implemented addMcpServerModal * Added sse and stdio ways of adding a server * Added no actions handling * added new mcp type to constants * Added headers to add mcp server modal * Changed mcp component to allow persistent mcp servers * fix input list component gradient * fix add server modal to patch when initial data is present, and to clean variables when switching tabs * changed message on add mcp server * Added required mutations for mcp page * Added mcp servers page * Changed design of page * Fixed delete problems and added delete confirmation * fixed wrong error parsing * changed padding * Made added server be used on mcp component * refactor: remove references to the langflow store (langflow-ai#8354) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (langflow-ai#8361) * Fixed search on sidebar * fixed infinite use effect * Fixed error handling * Fixed tool mode disappearing * fixed key pair button submitting form * Fixed bugs * Added required * Changed message * Disabled other tabs when modifying * Removed tool dropdown if the mcp server is empty * parsed name * fixed data test id not applying * fixed mcp component * Fixed component not working when only stdio command is present * refactored tests * Updated mcp_component to remove old non default keys * Added data-testids * Modified tests to include settings page functionality * [autofix.ci] apply automated fixes * Refactor out the core part of the mcp * [autofix.ci] apply automated fixes * Added placeholders on frontend components for errors * Fixed bugs with mcp component * updated bug * fix: made empty project appear instead of empty flows list when mcp is enabled (langflow-ai#8336) * try to fix * Fix MCP persistence * Update mcp_component.py * Update mcp.py * [autofix.ci] apply automated fixes * fix: Bump version numbers for langflow and langflow-base to 1.4.3 and 0.4.3 respectively * fix: Remove Igor Carvalho from maintainers list in pyproject.toml * fix(agent): reset model list when provider changes Switching the provider in the Agent component sometimes left models from the previous provider visible/selected. We now filter against the new , ensuring only models that belong to the active provider remain. * src/frontend/src/components/core/dropdownComponent/index.tsx – add guard when rebuilding * tests/extended/regression/general-bugs-dropdown-select-not-in-list.spec.ts – expand coverage for “model not in list” edge-cases Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> * refactor: remove references to the langflow store (langflow-ai#8354) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> fix: apikey lock issue and add option to disable tracking (langflow-ai#8361) * fix: made empty project appear instead of empty flows list when mcp is enabled (langflow-ai#8336) * fix mcp client async problems * fixed mcp sse access * [autofix.ci] apply automated fixes * Made values be maintained when refreshing page * Fixed bugs with tool mode and switching from tool mode to not tool mode * Update mcp_component.py * Update test_mcp_component.py * Don't expose file by name as external endpoint * Update files.py * Update files.py * Add checks for id * Refactor tests * Update test_mcp_component.py * Update test_mcp_component.py * Update test_mcp_component.py * updated tests * re-added placeholder on input for tests to not fail * updated session selector in order for tests to work --------- Co-authored-by: Eric Hare <ericrhare@gmail.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: Mike Fortman <michael.fortman@datastax.com> Co-authored-by: Cristian Lousa <cristian.lousa@gmail.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com> Co-authored-by: Deon Sanchez <69873175+deon-sanchez@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com> Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
Fixes a database lock issue by removing the use of asyncio.create_task when updating API key usage.
Adds the LANGFLOW_DISABLE_TRACK_APIKEY_USAGE environment variable to optionally disable usage tracking.
Default behavior is unchanged.
Summary by CodeRabbit
New Features
Documentation