{"record":{"id":"1e054c0391fd2ee2","repo":"apache/dolphinscheduler","slug":"task-instance-does-not-exist-in-project","errorCode":null,"errorMessage":"task instance does not exist in project","messagePattern":"task instance does not exist in project","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java","lineNumber":169,"sourceCode":"     * @param loginUser   login user\n     * @param projectCode project code\n     * @param taskInstId  task instance id\n     * @return log byte array\n     */\n    @Override\n    public byte[] getLogBytes(User loginUser, long projectCode, int taskInstId) {\n        // check user access for project\n        projectService.checkProjectAndAuthThrowException(loginUser, projectCode, DOWNLOAD_LOG);\n\n        // check whether the task instance can be found\n        TaskInstance task = taskInstanceDao.queryById(taskInstId);\n        if (task == null || StringUtils.isBlank(task.getHost())) {\n            throw new ServiceException(\"task instance is null or host is null\");\n        }\n\n        TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(task.getTaskCode());\n        if (taskDefinition != null && projectCode != taskDefinition.getProjectCode()) {\n            throw new ServiceException(\"task instance does not exist in project\");\n        }\n        return getLogBytes(task);\n    }\n\n    /**\n     * query log\n     *\n     * @param taskInstance task instance\n     * @param skipLineNum  skip line number\n     * @param limit        limit\n     * @return log string data\n     */\n    private String queryLog(TaskInstance taskInstance, int skipLineNum, int limit) {\n        final String logPath = taskInstance.getLogPath();\n        log.info(\"Query task instance log, taskInstanceId:{}, taskInstanceName:{}, host: {}, logPath:{}\",\n                taskInstance.getId(), taskInstance.getName(), taskInstance.getHost(), logPath);\n        if (StringUtils.isBlank(logPath)) {\n            throw new ServiceException(Status.QUERY_TASK_INSTANCE_LOG_ERROR,","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java#L151-L187","documentation":"Thrown by LoggerServiceImpl.getLogBytes when the task instance exists but its TaskDefinition's projectCode does not match the projectCode passed to the API. This is a cross-project access check: the log download is scoped to a project and the task does not belong to it.","triggerScenarios":"Calling GET /log/download-log with a valid taskInstId but a projectCode that differs from taskDefinition.getProjectCode() - e.g. passing the workflow's project instead of the task definition's project, or mixing IDs from two projects.","commonSituations":"Copying a download-log request from another project and only changing the instance ID; task definitions moved/imported into a different project; passing 0 or a default projectCode.","solutions":["Fetch the correct projectCode for the task's TaskDefinition (query by task.taskCode) and pass that to the API.","Verify the task instance belongs to the intended workflow/project in the UI before downloading.","Do not reuse request URLs across projects; each project's log download requires its own projectCode."],"exampleFix":"// before\nloggerService.getLogBytes(loginUser, wrongProjectCode, taskInstId);\n// after\nTaskInstance task = taskInstanceDao.queryById(taskInstId);\nTaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode());\nloggerService.getLogBytes(loginUser, def.getProjectCode(), taskInstId);","handlingStrategy":"validation","validationCode":"TaskInstance task = taskInstanceDao.queryById(taskInstId);\nTaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode());\nif (def == null || def.getProjectCode() != projectCode) {\n    throw new IllegalArgumentException(\"task does not belong to project \" + projectCode);\n}","typeGuard":"boolean belongsToProject(TaskDefinition def, long projectCode) {\n    return def != null && def.getProjectCode() == projectCode;\n}","tryCatchPattern":"try {\n    byte[] log = loggerService.getLogBytes(loginUser, projectCode, taskInstId);\n} catch (ServiceException e) {\n    // handle project mismatch\n}","preventionTips":["Derive projectCode from the task's TaskDefinition rather than hardcoding.","Never reuse download-log URLs across projects.","Check the task's project in the UI before downloading."],"tags":["dolphinscheduler","project-mismatch","log-download"],"backgroundTag":"entity-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}