{"record":{"id":"dcf3eb5fd74097ca","repo":"apache/dolphinscheduler","slug":"update-environment-error","errorCode":"UPDATE_ENVIRONMENT_ERROR","errorMessage":"Status.UPDATE_ENVIRONMENT_ERROR","messagePattern":"Status\\.UPDATE_ENVIRONMENT_ERROR","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java","lineNumber":363,"sourceCode":"\n        Set<String> deleteWorkerGroupSet = SetUtils.difference(existWorkerGroupSet, workerGroupSet).toSet();\n        Set<String> addWorkerGroupSet = SetUtils.difference(workerGroupSet, existWorkerGroupSet).toSet();\n\n        // verify whether the relation of this environment and worker groups can be adjusted\n        checkUsedEnvironmentWorkerGroupRelation(deleteWorkerGroupSet, name, code);\n\n        Environment env = new Environment();\n        env.setCode(code);\n        env.setName(name);\n        env.setConfig(config);\n        env.setDescription(desc);\n        env.setOperator(loginUser.getId());\n        env.setUpdateTime(new Date());\n\n        int update =\n                environmentMapper.update(env, new UpdateWrapper<Environment>().lambda().eq(Environment::getCode, code));\n        if (update <= 0) {\n            throw new ServiceException(Status.UPDATE_ENVIRONMENT_ERROR, name);\n        }\n        deleteWorkerGroupSet.forEach(key -> {\n            if (StringUtils.isNotEmpty(key)) {\n                relationMapper.delete(new QueryWrapper<EnvironmentWorkerGroupRelation>()\n                        .lambda()\n                        .eq(EnvironmentWorkerGroupRelation::getEnvironmentCode, code)\n                        .eq(EnvironmentWorkerGroupRelation::getWorkerGroup, key));\n            }\n        });\n        addWorkerGroupSet.forEach(key -> {\n            if (StringUtils.isNotEmpty(key)) {\n                EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation();\n                relation.setEnvironmentCode(code);\n                relation.setWorkerGroup(key);\n                relation.setUpdateTime(new Date());\n                relation.setCreateTime(new Date());\n                relation.setOperator(loginUser.getId());\n                relationMapper.insert(relation);","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java#L345-L381","documentation":"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).","triggerScenarios":"Calling updateEnvironmentByCode with an environment code that no longer exists in t_ds_environment (deleted concurrently, or wrong code supplied).","commonSituations":"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.","solutions":["Verify the environment code exists via GET /environments before updating","Refresh the environment list in the UI and retry with the current code","If scripting, look up the code by name with queryByEnvironmentName instead of hardcoding","Check for concurrent deletes by other users"],"exampleFix":"// before\nenvironmentService.updateEnvironmentByCode(loginUser, 12345L, name, desc, config, workerGroups); // code gone\n// after\nEnvironment env = environmentMapper.queryByEnvironmentCode(12345L);\nif (env != null) {\n    environmentService.updateEnvironmentByCode(loginUser, 12345L, name, desc, config, workerGroups);\n}","handlingStrategy":"validation","validationCode":"Environment env = environmentMapper.queryByEnvironmentCode(code);\nif (env == null) {\n    throw new IllegalStateException(\"Environment \" + code + \" no longer exists\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    environmentService.updateEnvironmentByCode(loginUser, code, name, desc, config, workerGroups);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.UPDATE_ENVIRONMENT_ERROR.getCode()) {\n        // reload environment list; code is stale/deleted\n    } else { throw e; }\n}","preventionTips":["Re-fetch the environment before each update; never cache codes across sessions","Avoid hardcoding environment codes in scripts — look them up by name","Handle concurrent edits with a refresh-and-retry flow"],"tags":["dolphinscheduler","environment","database-update","stale-data"],"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-14T00:17:10.932Z"}