{"record":{"id":"a6c5401bb4112f63","repo":"theonedev/onedev","slug":"pull-request-is-closed-a6c540","errorCode":null,"errorMessage":"Pull request is closed","messagePattern":"Pull request is closed","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/PullRequestResource.java","lineNumber":491,"sourceCode":"\t\t\t\t.findFirst()\n\t\t\t\t.orElse(null);\n\t\tif (assignment != null)\n\t\t\tpullRequestAssignmentService.delete(assignment);\n\n\t\treturn Response.ok().build();\n\t}\n\t\n\t@Api(order=1500)\n\t@Path(\"/{requestId}/merge-strategy\")\n    @POST\n    public Response setMergeStrategy(@PathParam(\"requestId\") Long requestId, @NotNull MergeStrategy mergeStrategy) {\n\t\tPullRequest request = pullRequestService.load(requestId);\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n    \tif (!SecurityUtils.canModifyPullRequest(subject, request))\n\t\t\tthrow new UnauthorizedException();\n\t\tif (!request.isOpen())\n\t\t\tthrow new NotAcceptableException(\"Pull request is closed\");\n\t\tpullRequestChangeService.changeMergeStrategy(user, request, mergeStrategy);\n\t\treturn Response.ok().build();\n    }\n\t\n\t@Api(order=1550)\n\t@Path(\"/{requestId}/auto-merge\")\n\t@POST\n\tpublic Response setAutoMerge(@PathParam(\"requestId\") Long requestId, @NotNull AutoMergeData data) {\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n\t\tPullRequest request = pullRequestService.load(requestId);\n\t\tif (!SecurityUtils.canModifyPullRequest(subject, request) || !SecurityUtils.canWriteCode(subject, request.getProject()))\n\t\t\tthrow new UnauthorizedException();\n\t\tif (!request.isOpen())\n\t\t\tthrow new NotAcceptableException(\"Pull request is closed\");\n\n\t\tif (data.isEnabled() && request.checkMergeCondition() == null)\n\t\t\tthrow new NotAcceptableException(\"This pull request is not eligible for auto-merge, as it can be merged directly now\");","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/PullRequestResource.java#L473-L509","documentation":"NotAcceptableException (HTTP 400) thrown from POST /pull-requests/{requestId}/merge-strategy when the pull request is no longer open (request.isOpen() is false). A merge strategy can only be configured on open pull requests; closed, merged, or discarded requests reject the change.","triggerScenarios":"Calling setMergeStrategy on a PR that was already merged, discarded/closed, or closed automatically (e.g. by branch deletion or target commit pushed), after another thread closed it.","commonSituations":"Automation races: script fetched PR list, PR got merged before the strategy update; UI stale tab submits on a closed PR; branch was deleted causing auto-close.","solutions":["Re-fetch the pull request state and confirm it is open before calling the endpoint.","If the PR is merged, there is nothing to configure — operate on the next open PR.","Reopen the discarded PR (if possible) before setting the merge strategy, or skip closed PRs in batch scripts by filtering on status=open."],"exampleFix":"// before\nrequests.post(f\"{url}/api/pull-requests/{pr_id}/merge-strategy\", data=\"SQUASH_ALL_COMMITS\")\n// after\npr = get_pull_request(pr_id)\nif pr[\"status\"] == \"OPEN\":\n    requests.post(f\"{url}/api/pull-requests/{pr_id}/merge-strategy\", data=\"SQUASH_ALL_COMMITS\")","handlingStrategy":"validation","validationCode":"const pr = await api.getPullRequest(requestId);\nif (pr.status !== \"OPEN\") throw new Error(`Pull request ${requestId} is ${pr.status}; merge strategy can only be set on open PRs`);","typeGuard":null,"tryCatchPattern":"try {\n  await api.setMergeStrategy(requestId, strategy);\n} catch (e) {\n  if (e.status === 400 && /closed/.test(e.body)) {\n    // refresh PR state; skip or reopen\n  } else throw e;\n}","preventionTips":["Re-fetch PR status immediately before configuring merge settings","Filter batch scripts to status=open","Handle the merged/disclosed race: catch 400 'Pull request is closed' and continue gracefully"],"tags":["pull-request","merge","state"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}