{"record":{"id":"0b87b09793780377","repo":"theonedev/onedev","slug":"issue-not-found-by-id-issueid","errorCode":null,"errorMessage":"Issue not found by id: ${issueId}","messagePattern":"Issue 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":124,"sourceCode":"\t\tProject project = projectService.load(data.getProjectId());\n\t\tif (!SecurityUtils.canCreateWorkspaces(subject, project))\n\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","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L106-L142","documentation":"OneDev throws this 406 NotAcceptableException when the optional issueId in the workspace creation request does not match any existing issue. issueService.get(id) returns null for unknown ids and the endpoint rejects the request.","triggerScenarios":"POSTing to the workspace REST resource with data.issueId set to an id that does not exist in the database (deleted issue, typo, id from another OneDev instance).","commonSituations":"Automation scripts hardcoding issue ids after issues were deleted or re-imported with different ids; passing a pull-request id or build number by mistake; stale links saved in external tooling.","solutions":["Confirm the issue id exists: open /<project>/issues/<id> in OneDev or query the issues REST resource first.","Remove the issueId field from the request payload if linking an issue is not required (it is optional).","Fix automations to resolve the issue id dynamically (e.g. by issue number/key) instead of hardcoding it."],"exampleFix":"// before\ndata.setIssueId(4321L); // guessed id\n// after\nIssue issue = OneDev.getInstance(IssueManager.class).find(project, \"#123\");\nif (issue != null) data.setIssueId(issue.getId());","handlingStrategy":"validation","validationCode":"if (data.getIssueId() != null && issueService.get(data.getIssueId()) == null)\n    throw new IllegalArgumentException(\"Issue \" + data.getIssueId() + \" does not exist\");","typeGuard":"Issue findIssue(Long id) {\n    return id == null ? null : issueService.get(id); // null-check before use\n}","tryCatchPattern":"try {\n    workspaceId = createWorkspace(data);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().startsWith(\"Issue not found\")) data.setIssueId(null); // retry without issue link\n    else throw e;\n}","preventionTips":["Resolve issue ids via the issues API rather than hardcoding","Treat issueId as optional and omit it when not required","Re-check ids after issue deletions or data migrations"],"tags":["rest-api","workspace","issue","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"}