Skip to content

Commit

Permalink
fix: consider remove_example_flows param on query on GET flows endpoi…
Browse files Browse the repository at this point in the history
…nt (#3967)

🐛 (flows.py): fix logic to remove example flows based on condition to improve data consistency and prevent errors
  • Loading branch information
Cristhianzl authored Oct 1, 2024
1 parent db9787c commit 2505836
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/backend/base/langflow/api/v1/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2505836

Please sign in to comment.