apache/dolphinscheduler · error · ServiceException

task instance does not exist in project

Error message

task instance does not exist in project

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java:169

     * @param loginUser   login user
     * @param projectCode project code
     * @param taskInstId  task instance id
     * @return log byte array
     */
    @Override
    public byte[] getLogBytes(User loginUser, long projectCode, int taskInstId) {
        // check user access for project
        projectService.checkProjectAndAuthThrowException(loginUser, projectCode, DOWNLOAD_LOG);

        // check whether the task instance can be found
        TaskInstance task = taskInstanceDao.queryById(taskInstId);
        if (task == null || StringUtils.isBlank(task.getHost())) {
            throw new ServiceException("task instance is null or host is null");
        }

        TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(task.getTaskCode());
        if (taskDefinition != null && projectCode != taskDefinition.getProjectCode()) {
            throw new ServiceException("task instance does not exist in project");
        }
        return getLogBytes(task);
    }

    /**
     * query log
     *
     * @param taskInstance task instance
     * @param skipLineNum  skip line number
     * @param limit        limit
     * @return log string data
     */
    private String queryLog(TaskInstance taskInstance, int skipLineNum, int limit) {
        final String logPath = taskInstance.getLogPath();
        log.info("Query task instance log, taskInstanceId:{}, taskInstanceName:{}, host: {}, logPath:{}",
                taskInstance.getId(), taskInstance.getName(), taskInstance.getHost(), logPath);
        if (StringUtils.isBlank(logPath)) {
            throw new ServiceException(Status.QUERY_TASK_INSTANCE_LOG_ERROR,

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Fetch the correct projectCode for the task's TaskDefinition (query by task.taskCode) and pass that to the API.
  2. Verify the task instance belongs to the intended workflow/project in the UI before downloading.
  3. Do not reuse request URLs across projects; each project's log download requires its own projectCode.

Example fix

// before
loggerService.getLogBytes(loginUser, wrongProjectCode, taskInstId);
// after
TaskInstance task = taskInstanceDao.queryById(taskInstId);
TaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode());
loggerService.getLogBytes(loginUser, def.getProjectCode(), taskInstId);
Defensive patterns

Strategy: validation

Validate before calling

TaskInstance task = taskInstanceDao.queryById(taskInstId);
TaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode());
if (def == null || def.getProjectCode() != projectCode) {
    throw new IllegalArgumentException("task does not belong to project " + projectCode);
}

Type guard

boolean belongsToProject(TaskDefinition def, long projectCode) {
    return def != null && def.getProjectCode() == projectCode;
}

Try / catch

try {
    byte[] log = loggerService.getLogBytes(loginUser, projectCode, taskInstId);
} catch (ServiceException e) {
    // handle project mismatch
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/1e054c0391fd2ee2. Report an issue: GitHub.