apache/dolphinscheduler · error · ServiceException

UPDATE_ENVIRONMENT_ERROR

UPDATE_ENVIRONMENT_ERROR

Error message

Status.UPDATE_ENVIRONMENT_ERROR

What it means

Thrown by updateEnvironmentByCode when the database UPDATE of the environment row affects zero rows, i.e. environmentMapper.update returns <= 0. This means no environment with the given code existed (or the update was a no-op against a missing row).

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java:363

        Set<String> deleteWorkerGroupSet = SetUtils.difference(existWorkerGroupSet, workerGroupSet).toSet();
        Set<String> addWorkerGroupSet = SetUtils.difference(workerGroupSet, existWorkerGroupSet).toSet();

        // verify whether the relation of this environment and worker groups can be adjusted
        checkUsedEnvironmentWorkerGroupRelation(deleteWorkerGroupSet, name, code);

        Environment env = new Environment();
        env.setCode(code);
        env.setName(name);
        env.setConfig(config);
        env.setDescription(desc);
        env.setOperator(loginUser.getId());
        env.setUpdateTime(new Date());

        int update =
                environmentMapper.update(env, new UpdateWrapper<Environment>().lambda().eq(Environment::getCode, code));
        if (update <= 0) {
            throw new ServiceException(Status.UPDATE_ENVIRONMENT_ERROR, name);
        }
        deleteWorkerGroupSet.forEach(key -> {
            if (StringUtils.isNotEmpty(key)) {
                relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>()
                        .lambda()
                        .eq(EnvironmentWorkerGroupRelation::getEnvironmentCode, code)
                        .eq(EnvironmentWorkerGroupRelation::getWorkerGroup, key));
            }
        });
        addWorkerGroupSet.forEach(key -> {
            if (StringUtils.isNotEmpty(key)) {
                EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation();
                relation.setEnvironmentCode(code);
                relation.setWorkerGroup(key);
                relation.setUpdateTime(new Date());
                relation.setCreateTime(new Date());
                relation.setOperator(loginUser.getId());
                relationMapper.insert(relation);

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Verify the environment code exists via GET /environments before updating
  2. Refresh the environment list in the UI and retry with the current code
  3. If scripting, look up the code by name with queryByEnvironmentName instead of hardcoding
  4. Check for concurrent deletes by other users

Example fix

// before
environmentService.updateEnvironmentByCode(loginUser, 12345L, name, desc, config, workerGroups); // code gone
// after
Environment env = environmentMapper.queryByEnvironmentCode(12345L);
if (env != null) {
    environmentService.updateEnvironmentByCode(loginUser, 12345L, name, desc, config, workerGroups);
}
Defensive patterns

Strategy: validation

Validate before calling

Environment env = environmentMapper.queryByEnvironmentCode(code);
if (env == null) {
    throw new IllegalStateException("Environment " + code + " no longer exists");
}

Try / catch

try {
    environmentService.updateEnvironmentByCode(loginUser, code, name, desc, config, workerGroups);
} catch (ServiceException e) {
    if (e.getCode() == Status.UPDATE_ENVIRONMENT_ERROR.getCode()) {
        // reload environment list; code is stale/deleted
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling updateEnvironmentByCode with an environment code that no longer exists in t_ds_environment (deleted concurrently, or wrong code supplied).

Common situations: Two admins editing the same environment where one deletes it while the other saves; stale UI data holding a code from before a delete; passing code=0 or a mistyped code from a script.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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