-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for running flows by endpoint name (#2012)
* feat: Add support for running flows by endpoint name This commit modifies the `simplified_run_flow` endpoint in `endpoints.py` to allow running flows using the endpoint name instead of the flow ID. It introduces a new route parameter `flow_id_or_name` which can accept either a UUID or a string representing the endpoint name. The code first attempts to parse the parameter as a UUID, and if that fails, it queries the database to find a flow with the matching endpoint name. This change improves the usability of the API by providing an alternative way to identify flows for execution. * feat: Add endpoint_name field to FlowType This commit adds the `endpoint_name` field to the `FlowType` interface in the `index.ts` file. The `endpoint_name` field is an optional string that represents the name of the endpoint associated with the flow. This change allows for more flexibility in identifying flows by endpoint name instead of just the flow ID. It improves the usability of the codebase by providing an alternative way to reference flows. * 🐛 (endpoints.py): change type of flow_id_or_name parameter from Union[str, UUID] to str to simplify the API and improve readability * feat: Add migration utility functions for table, column, foreign key, and constraint existence checks This commit adds utility functions to the `migration.py` module in the `langflow.utils` package. These functions provide convenient ways to check the existence of tables, columns, foreign keys, and constraints in a database using SQLAlchemy. The functions `table_exists`, `column_exists`, `foreign_key_exists`, and `constraint_exists` take the table name, column name, foreign key name, and constraint name respectively, along with the SQLAlchemy engine or connection object. They use the `Inspector` class from `sqlalchemy.engine.reflection` to retrieve the necessary information and return a boolean value indicating whether the specified element exists in the database. These utility functions improve the readability and maintainability of the codebase by encapsulating the common existence checks in a reusable and modular way. * feat: Add unique constraints for per-user folders and flows This commit adds unique constraints for per-user folders and flows in the database. It introduces the `unique_folder_name` constraint for the `folder` table, ensuring that each user can have only one folder with a specific name. Similarly, it adds the `unique_flow_endpoint_name` and `unique_flow_name` constraints for the `flow` table, enforcing uniqueness of endpoint names and flow names per user. These constraints improve data integrity and prevent duplicate entries in the database, providing a more robust and reliable system. * feat: Add poetry installation and caching steps to GitHub Actions workflow This commit updates the GitHub Actions workflow file `action.yml` to include additional steps for installing poetry and caching its dependencies. The `run` step now installs poetry using the specified version and ensures that the poetry binary is available in the PATH. Additionally, the workflow now includes a step to restore pip and poetry cached dependencies using the `actions/cache` action. These changes improve the workflow by providing a more efficient and reliable way to manage poetry dependencies and caching. * refactor: Improve error handling in update_flow function This commit improves the error handling in the `update_flow` function in `flows.py`. It adds a new `elif` condition to check if the exception is an instance of `HTTPException` and re-raises it. This ensures that any `HTTPException` raised during the update process is properly handled and returned as a response. Additionally, it removes the unnecessary `else` block and simplifies the code logic. This refactor enhances the reliability and maintainability of the `update_flow` function.
- Loading branch information
1 parent
9d2fe80
commit 94e8bf1
Showing
22 changed files
with
504 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
...ackend/base/langflow/alembic/versions/1c79524817ed_add_unique_constraints_per_user_in_.py
This file contains 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,42 @@ | ||
"""Add unique constraints per user in folder table | ||
Revision ID: 1c79524817ed | ||
Revises: 3bb0ddf32dfb | ||
Create Date: 2024-05-29 23:12:09.146880 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
from sqlalchemy.engine.reflection import Inspector | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "1c79524817ed" | ||
down_revision: Union[str, None] = "3bb0ddf32dfb" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
constraints_names = [constraint["name"] for constraint in inspector.get_unique_constraints("folder")] | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("folder", schema=None) as batch_op: | ||
if "unique_folder_name" not in constraints_names: | ||
batch_op.create_unique_constraint("unique_folder_name", ["user_id", "name"]) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
constraints_names = [constraint["name"] for constraint in inspector.get_unique_constraints("folder")] | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("folder", schema=None) as batch_op: | ||
if "unique_folder_name" in constraints_names: | ||
batch_op.drop_constraint("unique_folder_name", type_="unique") | ||
|
||
# ### end Alembic commands ### |
54 changes: 54 additions & 0 deletions
54
...d/base/langflow/alembic/versions/3bb0ddf32dfb_add_unique_constraints_per_user_in_flow_.py
This file contains 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,54 @@ | ||
"""Add unique constraints per user in flow table | ||
Revision ID: 3bb0ddf32dfb | ||
Revises: a72f5cf9c2f9 | ||
Create Date: 2024-05-29 23:08:43.935040 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
from sqlalchemy.engine.reflection import Inspector | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "3bb0ddf32dfb" | ||
down_revision: Union[str, None] = "a72f5cf9c2f9" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
indexes_names = [index["name"] for index in inspector.get_indexes("flow")] | ||
constraints_names = [constraint["name"] for constraint in inspector.get_unique_constraints("flow")] | ||
with op.batch_alter_table("flow", schema=None) as batch_op: | ||
if "ix_flow_endpoint_name" in indexes_names: | ||
batch_op.drop_index("ix_flow_endpoint_name") | ||
batch_op.create_index(batch_op.f("ix_flow_endpoint_name"), ["endpoint_name"], unique=False) | ||
if "unique_flow_endpoint_name" not in constraints_names: | ||
batch_op.create_unique_constraint("unique_flow_endpoint_name", ["user_id", "endpoint_name"]) | ||
if "unique_flow_name" not in constraints_names: | ||
batch_op.create_unique_constraint("unique_flow_name", ["user_id", "name"]) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
indexes_names = [index["name"] for index in inspector.get_indexes("flow")] | ||
constraints_names = [constraint["name"] for constraint in inspector.get_unique_constraints("flow")] | ||
with op.batch_alter_table("flow", schema=None) as batch_op: | ||
if "unique_flow_name" in constraints_names: | ||
batch_op.drop_constraint("unique_flow_name", type_="unique") | ||
if "unique_flow_endpoint_name" in constraints_names: | ||
batch_op.drop_constraint("unique_flow_endpoint_name", type_="unique") | ||
if "ix_flow_endpoint_name" in indexes_names: | ||
batch_op.drop_index(batch_op.f("ix_flow_endpoint_name")) | ||
batch_op.create_index("ix_flow_endpoint_name", ["endpoint_name"], unique=1) | ||
|
||
# ### end Alembic commands ### |
52 changes: 52 additions & 0 deletions
52
src/backend/base/langflow/alembic/versions/a72f5cf9c2f9_add_endpoint_name_col.py
This file contains 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,52 @@ | ||
"""Add endpoint name col | ||
Revision ID: a72f5cf9c2f9 | ||
Revises: 29fe8f1f806b | ||
Create Date: 2024-05-29 21:44:04.240816 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
import sqlmodel | ||
from alembic import op | ||
from sqlalchemy.engine.reflection import Inspector | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "a72f5cf9c2f9" | ||
down_revision: Union[str, None] = "29fe8f1f806b" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
column_names = [column["name"] for column in inspector.get_columns("flow")] | ||
indexes = inspector.get_indexes("flow") | ||
index_names = [index["name"] for index in indexes] | ||
with op.batch_alter_table("flow", schema=None) as batch_op: | ||
if "endpoint_name" not in column_names: | ||
batch_op.add_column(sa.Column("endpoint_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True)) | ||
if "ix_flow_endpoint_name" not in index_names: | ||
batch_op.create_index(batch_op.f("ix_flow_endpoint_name"), ["endpoint_name"], unique=True) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) # type: ignore | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
column_names = [column["name"] for column in inspector.get_columns("flow")] | ||
indexes = inspector.get_indexes("flow") | ||
index_names = [index["name"] for index in indexes] | ||
with op.batch_alter_table("flow", schema=None) as batch_op: | ||
if "ix_flow_endpoint_name" in index_names: | ||
batch_op.drop_index(batch_op.f("ix_flow_endpoint_name")) | ||
if "endpoint_name" in column_names: | ||
batch_op.drop_column("endpoint_name") | ||
|
||
# ### end Alembic commands ### |
This file contains 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 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 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.