{"record":{"id":"219a4f96639be68e","repo":"apache/dolphinscheduler","slug":"the-task-instance-is-not-under-the-project-proje","errorCode":null,"errorMessage":"The task instance is not under the project: {projectCode}","messagePattern":"The task instance is not under the project: (.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java","lineNumber":204,"sourceCode":"\n    /**\n     * change one task instance's state from failure to forced success\n     *\n     * @param loginUser      login user\n     * @param projectCode    project code\n     * @param taskInstanceId task instance id\n     * @return the result code and msg\n     */\n    @Transactional\n    @Override\n    public void forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {\n        projectService.checkHasProjectWritePermissionThrowException(loginUser, projectCode);\n\n        TaskInstance task = taskInstanceDao.queryOptionalById(taskInstanceId)\n                .orElseThrow(() -> new ServiceException(Status.TASK_INSTANCE_NOT_FOUND));\n\n        if (task.getProjectCode() != projectCode) {\n            throw new ServiceException(\"The task instance is not under the project: \" + projectCode);\n        }\n\n        WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId())\n                .orElseThrow(\n                        () -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, task.getWorkflowInstanceId()));\n        if (!workflowInstance.getState().isFinalState()) {\n            throw new ServiceException(\"The workflow instance is not finished: \" + workflowInstance.getState()\n                    + \" cannot force start task instance\");\n        }\n\n        // check whether the task instance state type is failure or cancel\n        if (!task.getState().isFailure() && !task.getState().isKill()) {\n            throw new ServiceException(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskInstanceId, task.getState());\n        }\n\n        // change the state of the task instance\n        task.setState(TaskExecutionStatus.FORCED_SUCCESS);\n        task.setEndTime(new Date());","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java#L186-L222","documentation":"Thrown by TaskInstanceServiceImpl.forceTaskSuccess when the task instance being force-succeeded belongs to a different project than the projectCode supplied in the request. It is a tenant/project scoping guard: DolphinScheduler requires the task instance to reside under the project the caller claims it is in. The raw string message (not a Status enum) means the client passed a mismatched projectCode/taskInstanceId pair.","triggerScenarios":"Calling the force-task-success API where task.getProjectCode() != projectCode, i.e. the taskInstanceId resolves to a task under a different project than the projectCode path/body parameter.","commonSituations":"Using a stale taskInstanceId copied from another project; copy-pasting an example curl with the wrong projectCode; automation that looks up task IDs in a global table instead of per-project; projects renamed/re-created so codes changed.","solutions":["Verify the taskInstanceId actually belongs to the projectCode you pass (query the task instance list scoped to that project first).","Correct the projectCode in your request URL/body to match the project that owns the task.","If automating, resolve the task's project via the API instead of hardcoding the code.","Ensure your user has write permission on the correct project (a wrong project often also fails the earlier permission check)."],"exampleFix":"// before\ncurl -X POST '.../projects/123456789/task-instance/987/force-success'\n// after\n// look up the task's real project code first, then use it\ncurl -X POST \".../projects/${TASK_PROJECT_CODE}/task-instance/${TASK_INSTANCE_ID}/force-success\"","handlingStrategy":"validation","validationCode":"// Java caller: confirm the task belongs to the project before calling\nTaskInstanceResponse t = taskInstanceService.queryByInstanceId(id);\nif (t == null || !Objects.equals(t.getProjectCode(), projectCode)) {\n    throw new IllegalArgumentException(\"task \" + id + \" is not in project \" + projectCode);\n}","typeGuard":"boolean belongsToProject(TaskInstance t, long projectCode) { return t != null && t.getProjectCode() == projectCode; }","tryCatchPattern":"try {\n    taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);\n} catch (ServiceException e) {\n    if (e.getMessage().contains(\"not under the project\")) {\n        // re-resolve correct projectCode for this task instance\n    }\n}","preventionTips":["Always resolve projectCode from the task instance, never hardcode","Scope task-id lookups to the project","Beware stale ids copied from other projects/environments"],"tags":["api","task-instance","project-scoping","validation"],"backgroundTag":"record-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}