From 56523a7f2d05868c14e6b3abae01f740ee96b1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 7 Aug 2024 21:44:21 +0200 Subject: [PATCH] feat: flag to disable transaction and vertex_builds writes (#3031) * feat: flag to disable transaction and vertex_builds writes * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/backend/base/langflow/graph/utils.py | 9 +++++++-- src/backend/base/langflow/services/settings/base.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/graph/utils.py b/src/backend/base/langflow/graph/utils.py index d8fd9bc8b..41b20c135 100644 --- a/src/backend/base/langflow/graph/utils.py +++ b/src/backend/base/langflow/graph/utils.py @@ -14,7 +14,7 @@ from langflow.services.database.models.transactions.crud import log_transaction from langflow.services.database.models.vertex_builds.crud import log_vertex_build as crud_log_vertex_build from langflow.services.database.models.vertex_builds.model import VertexBuildBase from langflow.services.database.utils import session_getter -from langflow.services.deps import get_db_service +from langflow.services.deps import get_db_service, get_settings_service from loguru import logger if TYPE_CHECKING: @@ -132,6 +132,8 @@ async def log_transaction( flow_id: Union[str, UUID], source: "Vertex", status, target: Optional["Vertex"] = None, error=None ) -> None: try: + if not get_settings_service().settings.transactions_storage_enabled: + return inputs = _vertex_to_primitive_dict(source) transaction = TransactionBase( vertex_id=source.id, @@ -159,6 +161,8 @@ def log_vertex_build( artifacts: Optional[dict] = None, ): try: + if not get_settings_service().settings.vertex_builds_storage_enabled: + return vertex_build = VertexBuildBase( flow_id=flow_id, id=vertex_id, @@ -166,7 +170,8 @@ def log_vertex_build( params=str(params) if params else None, # ugly hack to get the model dump with weird datatypes data=json.loads(data.model_dump_json()), - artifacts=artifacts, + # ugly hack to get the model dump with weird datatypes + artifacts=json.loads(json.dumps(artifacts, default=str)), ) with session_getter(get_db_service()) as session: inserted = crud_log_vertex_build(session, vertex_build) diff --git a/src/backend/base/langflow/services/settings/base.py b/src/backend/base/langflow/services/settings/base.py index b028294bd..658edd57e 100644 --- a/src/backend/base/langflow/services/settings/base.py +++ b/src/backend/base/langflow/services/settings/base.py @@ -146,6 +146,10 @@ class Settings(BaseSettings): do_not_track: bool = False """If set to True, Langflow will not track telemetry.""" telemetry_base_url: str = "https://langflow.gateway.scarf.sh" + transactions_storage_enabled: bool = True + """If set to True, Langflow will track transactions between flows.""" + vertex_builds_storage_enabled: bool = True + """If set to True, Langflow will keep track of each vertex builds (outputs) in the UI for any flow.""" @field_validator("user_agent", mode="after") @classmethod