theonedev/onedev · error · NotAcceptableException

Cannot delete pull request "${request.getReference().toStrin

Error message

Cannot delete pull request "${request.getReference().toString(request.getProject())}" as it has workspaces

What it means

OneDev refuses to delete a pull request that still has linked code workspaces (dev environments attached to the PR). checkNoWorkspaces throws this NotAcceptableException before doDelete to avoid orphaning active workspace instances. The PR reference is included in the message for context.

Source

Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java:234

			numberGenerator = new SequenceGenerator(PullRequest.class, clusterService, dao);
		return numberGenerator;
	}

	public Object writeReplace() throws ObjectStreamException {
		return new ManagedSerializedForm(PullRequestService.class);
	}

	@Transactional
	@Override
	public void delete(PullRequest request) {
		checkNoWorkspaces(request);
		doDelete(request);
		listenerRegistry.post(new PullRequestDeleted(request));
	}

	private void checkNoWorkspaces(PullRequest request) {
		if (request.getWorkspaces().size() > 0) {
			throw new NotAcceptableException("Cannot delete pull request \""
					+ request.getReference().toString(request.getProject()) + "\" as it has workspaces");
		}
	}

	private void doDelete(PullRequest request) {
		Collection<String> refs = Lists.newArrayList(
				request.getHeadRef(), request.getMergeRef(), request.getBaseRef(), request.getBuildRef());
		for (PullRequestUpdate update: request.getUpdates())
			refs.add(update.getHeadRef());

		gitService.deleteRefs(request.getTargetProject(), refs);

    	Query<?> query = getSession().createQuery(String.format(
    			"update CodeComment set %s=null where %s=:request",
    			CodeComment.PROP_COMPARE_CONTEXT + "." + CompareContext.PROP_PULL_REQUEST,
    			CodeComment.PROP_COMPARE_CONTEXT + "." + CompareContext.PROP_PULL_REQUEST));
    	query.setParameter("request", request);
    	query.executeUpdate();

View on GitHub (pinned to d44925c47c)

Solutions

  1. Delete or terminate the PR's workspaces first, then retry the delete
  2. If workspaces are stale, clean them up (workspace service / admin UI) before deleting the PR
  3. Check request.getWorkspaces().isEmpty() before calling delete

Example fix

// before
prService.delete(request); // fails while workspaces exist
// after
if (request.getWorkspaces().isEmpty())
    prService.delete(request);
else
    request.getWorkspaces().forEach(workspaceService::delete);
Defensive patterns

Strategy: validation

Validate before calling

if (!request.getWorkspaces().isEmpty())
    throw new IllegalStateException("delete PR first requires removing its workspaces");

Try / catch

try {
    prService.delete(request);
} catch (NotAcceptableException e) {
    // surface that workspaces must be deleted first
}

Prevention

When it happens

Trigger: Calling DefaultPullRequestService.delete(request) (directly or via REST DELETE) while request.getWorkspaces().size() > 0 — i.e. at least one workspace created from the PR still exists.

Common situations: Cleaning up old PRs while developers still have dev environments open from them; automated cleanup scripts hitting PRs whose workspaces were never torn down; project admin bulk-deleting stale PRs.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/1714bee5b4c1f8eb. Report an issue: GitHub.