From f2bc8a47cc120f3fd8a8a6de42bbcf1cdea5f6ea Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 1 Oct 2024 09:18:02 -0300 Subject: [PATCH] fix: consider remove_example_flows param on query on GET flows endpoint (#3967) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 (flows.py): fix logic to remove example flows based on condition to improve data consistency and prevent errors --- 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 ceffae481867..7998e3582603 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]