-
Notifications
You must be signed in to change notification settings - Fork 9.7k
fix: enforce locked flows in backend #14192
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a84eb77
fix: enforce locked flows in backend
erichare 49932d7
fix: make flow lock checks atomic
erichare aa41e5a
Merge branch 'release-1.11.0' into fix/enforce-locked-flow-backend
erichare b4c8c76
fix: allow no-op updates to locked flows
erichare 0010c1f
fix: preserve locked flow saves
erichare 4a05462
fix: detect locked editor state when saving flows
erichare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/backend/base/langflow/services/database/models/flow/guards.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Application-level guards for locked flow mutations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Mapping | ||
|
|
||
| from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
|
||
| from langflow.services.database.models.flow.model import Flow | ||
|
|
||
| LOCKED_FLOW_DETAIL = "Flow is locked. Unlock it before making changes." | ||
|
|
||
|
|
||
| class LockedFlowError(RuntimeError): | ||
| """Raised when a mutation targets a locked flow.""" | ||
|
|
||
|
|
||
| async def lock_flow_for_update(session: AsyncSession, flow: Flow) -> None: | ||
| """Refresh *flow* while holding its database row lock until transaction end.""" | ||
| await session.refresh(flow, with_for_update=True) | ||
|
|
||
|
|
||
| def ensure_flow_unlocked(flow: Flow) -> None: | ||
| """Raise when *flow* is currently locked.""" | ||
| if getattr(flow, "locked", False) is True: | ||
| raise LockedFlowError(LOCKED_FLOW_DETAIL) | ||
|
|
||
|
|
||
| def ensure_flow_update_allowed(flow: Flow, update_data: Mapping[str, Any]) -> None: | ||
| """Allow updates to unlocked flows and unlock-only updates to locked flows. | ||
|
|
||
| API clients commonly send the full current flow when toggling the lock. We | ||
| therefore compare payload values with the persisted row and allow the | ||
| request when ``locked=False`` is the only effective change. | ||
| """ | ||
| if getattr(flow, "locked", False) is not True: | ||
| return | ||
|
|
||
| changed_fields = { | ||
| field_name for field_name, new_value in update_data.items() if getattr(flow, field_name, None) != new_value | ||
| } | ||
| if changed_fields == {"locked"} and update_data.get("locked") is False: | ||
| return | ||
|
|
||
| raise LockedFlowError(LOCKED_FLOW_DETAIL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.