{"record":{"id":"23f3876f02dc63fc","repo":"apache/dolphinscheduler","slug":"20004","errorCode":"20004","errorMessage":"resource not exist","messagePattern":"resource not exist","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java","lineNumber":129,"sourceCode":"        dataSource.setType(datasourceParam.getType());\n        dataSource.setConnectionParams(JSONUtils.toJsonString(connectionParam));\n        dataSource.setCreateTime(now);\n        dataSource.setUpdateTime(now);\n        try {\n            dataSourceDao.insert(dataSource);\n            return dataSource;\n        } catch (DuplicateKeyException ex) {\n            throw new ServiceException(Status.DATASOURCE_EXIST);\n        }\n    }\n\n    @Override\n    public DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam) {\n        DataSourceUtils.checkDatasourceParam(dataSourceParam);\n        // determine whether the data source exists\n        DataSource dataSource = dataSourceDao.queryById(dataSourceParam.getId());\n        if (dataSource == null) {\n            throw new ServiceException(Status.RESOURCE_NOT_EXIST);\n        }\n\n        if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,\n                DATASOURCE_UPDATE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        // check name can use or not\n        if (!dataSourceParam.getName().trim().equals(dataSource.getName()) && checkName(dataSourceParam.getName())) {\n            throw new ServiceException(Status.DATASOURCE_EXIST);\n        }\n        if (checkDescriptionLength(dataSourceParam.getNote())) {\n            throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR);\n        }\n        // check password，if the password is not updated, set to the old password.\n        ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(dataSourceParam);\n\n        String password = connectionParam.getPassword();","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java#L111-L147","documentation":"updateDataSource looks up the target by id via dataSourceDao.queryById; when no record matches, Status.RESOURCE_NOT_EXIST (code 20004) is thrown, meaning the datasource id in the request does not exist.","triggerScenarios":"PUT /datasources/{id} with an id that was deleted or never existed (queryById returns null).","commonSituations":"Stale UI tab after another user deleted the datasource; hardcoded ids from another environment; cleanup scripts removed the record before the update ran.","solutions":["Re-fetch the datasource list and use a valid id before updating.","If the datasource was deleted intentionally, recreate it instead of updating.","Guard automation: GET the datasource first, and create it when the GET returns 404."],"exampleFix":"// before\nupdateDatasource(user, paramWithId42); // id 42 deleted\n// after\nif (getDatasource(id42) == null) createDatasource(param); else updateDatasource(user, paramWithId42);","handlingStrategy":"validation","validationCode":"DataSource ds = api.getDatasource(id);\nif (ds == null) { throw new IllegalStateException(\"datasource \" + id + \" does not exist\"); }","typeGuard":"boolean exists(DataSource ds) { return ds != null && ds.getId() > 0; }","tryCatchPattern":"try { api.updateDataSource(user, param); } catch (ServiceException e) { if (e.getCode() == 20004) { /* recreate or refresh id list */ } else throw e; }","preventionTips":["Resolve datasource ids by name at run time, not hardcoded","Refresh UI state after deletions","GET the datasource before PUT"],"tags":["datasource","not-found","stale-reference"],"backgroundTag":"resource-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"}