{"record":{"id":"2b90004b33f2f634","repo":"theonedev/onedev","slug":"issue-does-not-belong-to-specified-project","errorCode":null,"errorMessage":"Issue does not belong to specified project","messagePattern":"Issue 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":126,"sourceCode":"\t\t\tthrow new UnauthorizedException();\n\n\t\tif (project.getHierarchyWorkspaceSpecs().stream()\n\t\t\t\t.noneMatch(it -> it.getName().equals(data.getSpecName()))) {\n\t\t\tthrow new NotAcceptableException(\"Workspace spec not found: \" + data.getSpecName());\n\t\t}\n\n\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\")","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L108-L144","documentation":"OneDev throws this 406 NotAcceptableException when the referenced issue exists but belongs to a project different from the project specified in the workspace creation request. A workspace can only link issues from the same project.","triggerScenarios":"POSTing to the workspace REST resource with project=X but issueId pointing at an issue in project Y.","commonSituations":"Cross-project automations that pass a global issue id without checking its project; users copying an issue link from a related project; bulk tooling that assumes issue ids are globally scoped to the chosen project.","solutions":["Verify issue.getProject() equals the target project before calling the API; pick an issue from the specified project.","Change the request's projectId to the project the issue actually belongs to (if that is the intended project).","Drop the issueId from the payload if the linkage is not essential.","Add a pre-check in tooling: resolve the issue via the project's issue list API instead of a bare global id."],"exampleFix":"// before\nIssue issue = issueService.get(data.getIssueId());\ndata.setProjectId(someOtherProject.getId());\n// after\nIssue issue = issueService.get(data.getIssueId());\nif (issue != null && issue.getProject().equals(project)) {\n    data.setProjectId(project.getId());\n}","handlingStrategy":"validation","validationCode":"Issue issue = issueService.get(data.getIssueId());\nif (issue != null && !issue.getProject().equals(project))\n    throw new IllegalArgumentException(\"Issue \" + issue.getNumber() + \" belongs to \" + issue.getProject().getPath());","typeGuard":"boolean issueInProject(Issue issue, Project project) {\n    return issue != null && issue.getProject().equals(project);\n}","tryCatchPattern":null,"preventionTips":["Always load issues through the target project's issue collection, not by global id","Add project-consistency assertions in automation before calling the workspace API","Keep (project, issueId) pairs together in configuration instead of bare ids"],"tags":["rest-api","workspace","issue","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"}