{"record":{"id":"8eb938c0c2ff1f88","repo":"theonedev/onedev","slug":"pull-request-does-not-belong-to-specified-project","errorCode":null,"errorMessage":"Pull request does not belong to specified project","messagePattern":"Pull request does not belong to specified project","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java","lineNumber":135,"sourceCode":"\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\");\n\t\tworkspaceService.reset(workspace);\n\t\treturn Response.ok().build();","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L117-L153","documentation":"OneDev throws this 406 NotAcceptableException when the referenced pull request exists but belongs to a project different from the project specified in the workspace creation request. Workspaces may only link pull requests from the same project.","triggerScenarios":"POSTing to the workspace REST resource with project=X but pullRequestId referencing a PR in project Y (including PRs on forks whose target is a different project).","commonSituations":"Cross-repo automation pipelines passing a PR id from an upstream project; users confusing a fork's PR with the target project's PR; batch scripts that look up PRs globally.","solutions":["Check request.getProject() equals the PR's target project before calling; use a PR belonging to the specified project.","Change the request's projectId to the project the PR belongs to.","Omit pullRequestId if the linkage is optional for the workflow."],"exampleFix":"// before\nPullRequest pr = pullRequestService.get(data.getPullRequestId());\nworkspaceService.create(user, fork, issue, pr, ...);\n// after\nPullRequest pr = pullRequestService.get(data.getPullRequestId());\nif (pr != null && pr.getProject().equals(project)) {\n    workspaceService.create(user, project, issue, pr, ...);\n}","handlingStrategy":"validation","validationCode":"PullRequest pr = pullRequestService.get(data.getPullRequestId());\nif (pr != null && !pr.getProject().equals(project))\n    throw new IllegalArgumentException(\"PR #\" + pr.getNumber() + \" belongs to \" + pr.getProject().getPath());","typeGuard":"boolean pullRequestInProject(PullRequest pr, Project project) {\n    return pr != null && pr.getProject().equals(project);\n}","tryCatchPattern":null,"preventionTips":["Pass the PR's target project as the workspace project, not the fork's project","Verify pr.getTargetProject()/project equality in pipeline code before workspace creation","Store (projectId, pullRequestId) together in tooling configuration"],"tags":["rest-api","workspace","pull-request","project-mismatch"],"backgroundTag":"invalid-argument-value","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"}