{"record":{"id":"bea932d188d4e762","repo":"theonedev/onedev","slug":"pull-request-not-found-by-id-pullrequestid","errorCode":null,"errorMessage":"Pull request not found by id: ${pullRequestId}","messagePattern":"Pull request not found by id: (.+?)","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java","lineNumber":133,"sourceCode":"\t\tObjectId commitId = ObjectId.fromString(data.getCommitHash());\n\t\tvar commit = project.getRevCommit(commitId, false);\n\t\tif (commit == null) \n\t\t\tthrow new NotAcceptableException(\"Commit not found: \" + data.getCommitHash());\n\n\t\tIssue issue = null;\n\t\tif (data.getIssueId() != null) {\n\t\t\tissue = issueService.get(data.getIssueId());\n\t\t\tif (issue == null)\n\t\t\t\tthrow new NotAcceptableException(\"Issue not found by id: \" + data.getIssueId());\n\t\t\tif (!issue.getProject().equals(project))\n\t\t\t\tthrow new NotAcceptableException(\"Issue does not belong to specified project\");\n\t\t}\n\n\t\tPullRequest request = null;\n\t\tif (data.getPullRequestId() != null) {\n\t\t\trequest = pullRequestService.get(data.getPullRequestId());\n\t\t\tif (request == null)\n\t\t\t\tthrow new NotAcceptableException(\"Pull request not found by id: \" + data.getPullRequestId());\n\t\t\tif (!request.getProject().equals(project))\n\t\t\t\tthrow new NotAcceptableException(\"Pull request does not belong to specified project\");\n\t\t}\n\n\t\tWorkspace workspace = workspaceService.create(user, project, issue, request, commitId,\n\t\t\t\tdata.getBranch(), data.getSpecName(), false);\n\t\treturn workspace.getId();\n\t}\n\n\t@Api(order=400, description=\"Reprovision inactive workspace\")\n\t@Path(\"/{workspaceId}/reprovision\")\n\t@POST\n\tpublic Response reprovisionWorkspace(@PathParam(\"workspaceId\") Long workspaceId) {\n\t\tWorkspace workspace = workspaceService.load(workspaceId);\n\t\tif (!SecurityUtils.canModifyOrDelete(workspace))\n\t\t\tthrow new UnauthorizedException();\n\t\tif (workspace.getStatus() != Status.INACTIVE)\n\t\t\tthrow new NotAcceptableException(\"Only inactive workspaces can be reprovisioned\");","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L115-L151","documentation":"OneDev throws this 406 NotAcceptableException when the optional pullRequestId in the workspace creation request does not match any existing pull request. pullRequestService.get(id) returns null for unknown ids.","triggerScenarios":"POSTing to the workspace REST resource with data.pullRequestId set to an id of a deleted pull request, a typo'd id, or an id from a different OneDev instance.","commonSituations":"Scripts referencing PR ids after the PR was deleted; confusing a PR number displayed in the UI with the internal entity id; stale configuration in external CI tooling.","solutions":["Confirm the pull request id exists by fetching it via the pull request REST resource or the OneDev UI URL /<project>/pulls/<id>.","Omit pullRequestId from the request if linking a PR is not required.","Update automations to resolve the PR id from the PR number dynamically."],"exampleFix":"// before\ndata.setPullRequestId(Long.valueOf(prNumberText)); // UI number, not id\n// after\nPullRequest pr = pullRequestService.find(project, prNumber);\nif (pr != null) data.setPullRequestId(pr.getId());","handlingStrategy":"validation","validationCode":"if (data.getPullRequestId() != null && pullRequestService.get(data.getPullRequestId()) == null)\n    throw new IllegalArgumentException(\"Pull request \" + data.getPullRequestId() + \" does not exist\");","typeGuard":"PullRequest findPullRequest(Long id) {\n    return id == null ? null : pullRequestService.get(id);\n}","tryCatchPattern":"try {\n    workspaceId = createWorkspace(data);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().startsWith(\"Pull request not found\")) data.setPullRequestId(null);\n    else throw e;\n}","preventionTips":["Look up PR ids via the pull request REST/Java API, never from displayed numbers","Purge stale PR references from scripts after PR deletion","Null-check optional PR links before sending the request"],"tags":["rest-api","workspace","pull-request","resource-not-found"],"backgroundTag":"record-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}