theonedev/onedev · error · NotAcceptableException

errorMessage (from checkDeleteSourceBranchCondition)

Error message

errorMessage (from checkDeleteSourceBranchCondition)

What it means

deleteSourceBranch throws the message from PullRequest.checkDeleteSourceBranchCondition() as a NotAcceptableException when the branch is not safe to delete. The guard rejects: PR not merged, source project/branch gone, source is the default branch, merge preview missing, head not up-to-date with the merge, or other open PRs targeting the branch. The thrown message is the exact condition error.

Source

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

		if (request.getSource().getObjectName(false) == null) {
			getGitService().createBranch(request.getSourceProject(), request.getSourceBranch(),
					request.getLatestUpdate().getHeadCommitHash());

			PullRequestChange change = new PullRequestChange();
			change.setDate(new Date());
			change.setData(new PullRequestSourceBranchRestoreData());
			change.setRequest(request);
			change.setUser(user);
			changeService.create(change, note);
		}
	}

	@Transactional
	@Override
	public void deleteSourceBranch(User user, PullRequest request, String note) {
        var errorMessage = request.checkDeleteSourceBranchCondition();
        if (errorMessage != null)
            throw new NotAcceptableException(errorMessage);

		if (request.getSource().getObjectName(false) != null) {
			projectService.deleteBranch(request.getSourceProject(), request.getSourceBranch());
			PullRequestChange change = new PullRequestChange();
			change.setDate(new Date());
			change.setData(new PullRequestSourceBranchDeleteData());
			change.setRequest(request);
			change.setUser(user);
			changeService.create(change, note);
		}
	}

	@Transactional
	@Override
	public void reopen(User user, PullRequest request, String note) {
        var errorMessage = request.checkReopenCondition();
        if (errorMessage != null)
            throw new NotAcceptableException(errorMessage);

View on GitHub (pinned to d44925c47c)

Solutions

  1. Merge the pull request first, then delete the branch
  2. Choose a non-default source branch — the default branch is never deletable this way
  3. Wait for/re-trigger merge preview so the head commit hash is current, or update the PR
  4. Close or retarget other open pull requests that use this branch as target
  5. Pre-check request.checkDeleteSourceBranchCondition() == null before calling

Example fix

// before
prService.deleteSourceBranch(user, request, "cleanup"); // 400 "Pull request not merged"
// after
if (request.isMerged() && request.checkDeleteSourceBranchCondition() == null)
    prService.deleteSourceBranch(user, request, "cleanup");
Defensive patterns

Strategy: validation

Validate before calling

String err = request.checkDeleteSourceBranchCondition();
boolean canDelete = err == null;

Try / catch

try {
    prService.deleteSourceBranch(user, request, note);
} catch (NotAcceptableException e) {
    // e.g. not merged yet, default branch, or other open PRs depend on it
}

Prevention

When it happens

Trigger: Calling DefaultPullRequestService.deleteSourceBranch(user, request, note) when checkDeleteSourceBranchCondition() returns non-null — e.g. "Pull request not merged", "Source branch is default branch", "Change not updated yet", or "Some other pull requests are opening to this branch".

Common situations: Trying to delete the source branch before the PR is merged; the source branch is the repo's default branch; the branch received new commits after the last PR update; other PRs still target that branch; automation deleting branches too early.

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/ba3cfbf54ae6983f. Report an issue: GitHub.