fix: consider remove_example_flows param on query on GET flows endpoint (#3967)

🐛 (flows.py): fix logic to remove example flows based on condition to improve data consistency and prevent errors
This commit is contained in:
Cristhian Zanforlin Lousa 2024-10-01 09:18:02 -03:00 • committed by GitHub
commit 2505836e51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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]