{"record":{"id":"7cc0dd44b0da815a","repo":"theonedev/onedev","slug":"iteration-is-not-defined-in-project-hierarchy-of-t","errorCode":null,"errorMessage":"Iteration is not defined in project hierarchy of the issue","messagePattern":"Iteration is not defined in project hierarchy of the issue","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/IssueResource.java","lineNumber":346,"sourceCode":"\n\t\tvar issueSetting = settingService.getIssueSetting();\n\t\t\n\t\tIssue issue = new Issue();\n\t\tissue.setTitle(data.getTitle());\n\t\tissue.setDescription(data.getDescription());\n\t\tissue.setConfidential(data.isConfidential());\n\t\tissue.setProject(project);\n\t\tissue.setSubmitDate(new Date());\n\t\tissue.setSubmitter(user);\n\t\tissue.setState(issueSetting.getInitialStateSpec().getName());\n\t\tif (data.getOwnEstimatedTime() != null)\n\t\t\tissue.setOwnEstimatedTime(data.getOwnEstimatedTime());\n\n\t\tif (data.getIterationIds() != null) {\n\t\t\tfor (Long iterationId : data.getIterationIds()) {\n\t\t\t\tIteration iteration = iterationService.load(iterationId);\n\t\t\t\tif (!iteration.getProject().isSelfOrAncestorOf(project))\n\t\t\t\t\tthrow new BadRequestException(\"Iteration is not defined in project hierarchy of the issue\");\n\t\t\t\tIssueSchedule schedule = new IssueSchedule();\n\t\t\t\tschedule.setIssue(issue);\n\t\t\t\tschedule.setIteration(iteration);\n\t\t\t\tissue.getSchedules().add(schedule);\n\t\t\t}\n\t\t}\n\n\t\tissue.setFieldValues(FieldUtils.getFieldValues(subject, project, data.fields));\n\t\tissueService.open(issue);\n\n\t\treturn issue.getId();\n    }\n\t\n\t@Api(order=1100)\n\t@Path(\"/{issueId}/title\")\n    @POST\n    public Response setTitle(@PathParam(\"issueId\") Long issueId, @NotEmpty String title) {\n\t\tIssue issue = issueService.load(issueId);","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/IssueResource.java#L328-L364","documentation":"During issue creation, each iterationId in the request is validated to belong to the issue's project or one of its ancestors. If the iteration's project is not self-or-ancestor of the issue's project, a BadRequestException (HTTP 400) is thrown. This keeps schedules consistent with the project hierarchy.","triggerScenarios":"POST to /api/issues with iterationIds containing the id of an iteration defined in an unrelated project (sibling, child, or another hierarchy) rather than the issue's project or an ancestor.","commonSituations":"Hard-coded iteration ids from another project in automation scripts; copying iteration ids between projects; iterating over all project iterations instead of filtering by hierarchy.","solutions":["Use iteration ids that belong to the issue's project or one of its ancestors.","Look up valid iterations via the iteration API filtered by the target project before posting.","Remove iterationIds from the request if scheduling is unnecessary."],"exampleFix":"// before\nPOST /api/issues {\"title\":\"t\",\"iterationIds\":[99]}  // 99 belongs to another project\n// after\nPOST /api/issues {\"title\":\"t\",\"iterationIds\":[12]}   // 12 is an iteration of the issue's project or ancestor","handlingStrategy":"validation","validationCode":"const validIterations = (await getIterations()).filter(it =>\n  it.project.path === projectPath || projectAncestors(projectPath).includes(it.project.path));\nconst bad = body.iterationIds?.filter(id => !validIterations.some(it => it.id === id));\nif (bad?.length) throw new Error(`Iterations not in project hierarchy: ${bad.join(',')}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve iteration ids from the target project's hierarchy at runtime, never hard-code.","Remember iteration ids are global; always map project-local names to ids.","Re-resolve ids after project restructuring."],"tags":["rest-api","iterations","project-hierarchy","validation"],"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-14T00:17:10.932Z"}