We were using a script from this question to make a copy of a workflow scheme that is shared between several projects and assign it to a specific project, so that they have base workflows but can make changes to their workflows without affecting other projects. The script works as expected, new workflow scheme with copies of each workflow is created and assigned to the project
But then we ran into a weird issue when editing the workflows.
If the project had issues before we copied the workflow, we didn't create any new issues, and we edit the workflow from "Project settings" page (using a link like <BASE_URL>/plugins/servlet/project-config/<PROJECT_KEY>/workflow/edit/?name=<WORKFLOW_NAME>), then it's somehow possible to delete the statuses from that workflow even though there are issues in that status that are associated with this workflow.
If we create new issues and move them into the same statuses before editing the workflow, everything works as expected and we get "Failed to remove a status" message.
If we go into the Administration (secure/admin/workflows/ViewWorkflowSteps.jspa) to edit the workflow instead of using the Project Settings page, Delete button is inactive for statuses that have issues in this status associated with this workflow.
Maybe there are some missing steps that we need to do after associating the new scheme with the project to make sure that all issues are properly associated with their workflows? Re-indexing the project doesn't seem to do anything though