Retire a shared node in use with ?detach=true

DELETE /flows/library/{name} still answers 409 while nodes use the source.
With detach=true each of them keeps a copy of the code, in the published
flow and the draft, the source is deleted and the running users rebuild.
This commit is contained in:
2026-10-15 09:48:47 +02:00
parent 96f4fa5a38
commit 0004e4b9bd
7 changed files with 114 additions and 2 deletions
+17 -2
View File
@@ -336,8 +336,23 @@ def read_library(controller: FlowControllerDep) -> Any:
@router.delete("/library/{lib_name}", response_model=Message)
async def delete_shared_node(lib_name: str, controller: FlowControllerDep) -> Any:
"""Remove a shared source, as long as no flow still runs it."""
async def delete_shared_node(
lib_name: str, controller: FlowControllerDep, detach: bool = False
) -> Any:
"""Remove a shared source, as long as no flow still runs it.
With ``detach``, every node using it keeps a copy of the code as its own
first, so the source can be retired while flows still use it.
"""
if detach:
running = await run_in_threadpool(controller.store.usages, lib_name, False)
try:
await run_in_threadpool(controller.store.detach_lib, lib_name)
except LibNotFound:
raise HTTPException(status_code=404, detail=f"No shared node '{lib_name}'")
for flow in sorted({usage.split(".", 1)[0] for usage in running}):
await controller.reload_flow(flow)
return Message(message=f"Deleted shared node '{lib_name}'")
used_by = controller.store.usages(lib_name)
if used_by:
raise HTTPException(