From 36df0df0d31fd68f21d8cc87222ec8335ffd5a17 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Mon, 30 Sep 2024 18:08:27 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(flows.py):=20fix=20logic=20to?= =?UTF-8?q?=20remove=20example=20flows=20based=20on=20condition=20to=20imp?= =?UTF-8?q?rove=20data=20consistency=20and=20prevent=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/base/langflow/api/v1/flows.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/api/v1/flows.py b/src/backend/base/langflow/api/v1/flows.py index ceffae48186..7998e358260 100644 --- a/src/backend/base/langflow/api/v1/flows.py +++ b/src/backend/base/langflow/api/v1/flows.py @@ -160,16 +160,20 @@ def read_flows( flows = [flow for flow in flows if flow.is_component] flow_ids = [flow.id for flow in flows] # with the session get the flows that DO NOT have a user_id + folder = session.exec(select(Folder).where(Folder.name == STARTER_FOLDER_NAME)).first() + if not remove_example_flows and not components_only: try: - folder = session.exec(select(Folder).where(Folder.name == STARTER_FOLDER_NAME)).first() - example_flows = folder.flows if folder else [] for example_flow in example_flows: if example_flow.id not in flow_ids: flows.append(example_flow) # type: ignore except Exception as e: logger.error(e) + + if remove_example_flows: + flows = [flow for flow in flows if flow.folder_id != folder.id] + except Exception as e: raise HTTPException(status_code=500, detail=str(e)) from e return [jsonable_encoder(flow) for flow in flows]