Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions backend/workflow_manager/workflow_v2/workflow_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,24 @@ def can_update_workflow(workflow_id: str) -> dict[str, Any]:
workflow: Workflow = Workflow.objects.get(pk=workflow_id)
if not workflow or workflow is None:
raise WorkflowDoesNotExistError()
used_count = Pipeline.objects.filter(workflow=workflow).count()
if used_count == 0:
used_count = APIDeployment.objects.filter(workflow=workflow).count()
return {"can_update": used_count == 0}

pipeline_names = list(
Pipeline.objects.filter(workflow=workflow).values_list(
"pipeline_name", flat=True
)
)
api_names = list(
APIDeployment.objects.filter(workflow=workflow).values_list(
"display_name", flat=True
)
)
total_usage = len(pipeline_names) + len(api_names)

return {
"can_update": total_usage == 0,
"pipeline_names": pipeline_names,
"api_names": api_names,
}
except Workflow.DoesNotExist:
logger.error(f"Error getting workflow: {id}")
raise WorkflowDoesNotExistError()
Expand Down
75 changes: 49 additions & 26 deletions frontend/src/components/workflows/workflow/Workflows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,60 @@ function Workflows() {
});
}

const canDeleteProject = async (id) => {
let status = false;
await projectApiService.canUpdate(id).then((res) => {
status = res?.data?.can_update || false;
});
return status;
const checkWorkflowUsage = async (id) => {
const res = await projectApiService.canUpdate(id);
return {
can_update: res?.data?.can_update || false,
pipeline_names: res?.data?.pipeline_names || [],
api_names: res?.data?.api_names || [],
};
};

const getUsageMessage = (workflowName, pipelineNames, apiNames) => {
const allNames = [...apiNames, ...pipelineNames];
const total = allNames.length;
if (total === 0) return "";
const firstName = `"${allNames[0]}"`;
if (total === 1) {
return `Cannot delete "${workflowName}" as it is used in ${firstName}.`;
}
const remaining = total - 1;
const pipelineLabel = remaining === 1 ? "pipeline" : "pipelines";
return `Cannot delete "${workflowName}" as it is used in ${firstName} and ${remaining} other API/ETL/Task ${pipelineLabel}.`;
};
Comment on lines +158 to 169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Empty error toast if can_update is false but backend returns no names.

If the backend returns can_update: false with empty pipeline_names and api_names (e.g., a race condition or backend bug), getUsageMessage returns "", resulting in a blank error notification at Line 192. Add a fallback message.

Suggested fix
     const total = allNames.length;
-    if (total === 0) return "";
+    if (total === 0)
+      return `Cannot delete "${workflowName}" as it is currently in use.`;
     const firstName = `"${allNames[0]}"`;
🤖 Prompt for AI Agents
In `@frontend/src/components/workflows/workflow/Workflows.jsx` around lines 158 -
169, getUsageMessage currently returns an empty string when can_update is false
but backend returns no pipeline_names/api_names, causing a blank error toast;
update the getUsageMessage function to return a sensible fallback message (e.g.,
`Cannot delete "<workflowName>" because it is in use.` or similar) when total
=== 0 so the UI always displays a readable error; ensure you update the return
for the total === 0 branch in getUsageMessage and keep existing
firstName/remaining logic intact.


const deleteProject = async (_evt, project) => {
const canDelete = await canDeleteProject(project.id);
if (canDelete) {
projectApiService
.deleteProject(project.id)
.then(() => {
getProjectList();
setAlertDetails({
type: "success",
content: "Workflow deleted successfully",
try {
const usage = await checkWorkflowUsage(project.id);
if (usage.can_update) {
projectApiService
.deleteProject(project.id)
.then(() => {
getProjectList();
setAlertDetails({
type: "success",
content: "Workflow deleted successfully",
});
})
.catch((err) => {
setAlertDetails(
handleException(err, `Unable to delete workflow ${project.id}`)
);
});
})
.catch((err) => {
setAlertDetails(
handleException(err, `Unable to delete workflow ${project.id}`)
);
} else {
setAlertDetails({
type: "error",
content: getUsageMessage(
project.workflow_name,
usage.pipeline_names,
usage.api_names
),
});
} else {
setAlertDetails({
type: "error",
content:
"Cannot delete this Workflow, since it is used in one or many of the API/ETL/Task pipelines",
});
}
} catch (err) {
setAlertDetails(
handleException(err, `Unable to delete workflow ${project.id}`)
);
}
};

Expand Down