{"record":{"id":"462684d9d27a7a68","repo":"apache/dolphinscheduler","slug":"10015","errorCode":"10015","errorMessage":"data source name already exists","messagePattern":"data source name already exists","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java","lineNumber":96,"sourceCode":"    @Autowired\n    private DataSourceUserDao datasourceUserDao;\n\n    private static final String TABLE = \"TABLE\";\n    private static final String VIEW = \"VIEW\";\n    private static final String[] TABLE_TYPES = new String[]{TABLE, VIEW};\n    private static final String TABLE_NAME = \"TABLE_NAME\";\n    private static final String COLUMN_NAME = \"COLUMN_NAME\";\n\n    @Override\n    public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) {\n        DataSourceUtils.checkDatasourceParam(datasourceParam);\n        if (!canOperatorPermissions(loginUser, null, AuthorizationType.DATASOURCE,\n                ApiFuncIdentificationConstant.DATASOURCE_CREATE_DATASOURCE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n        // check name can use or not\n        if (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        ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(datasourceParam);\n\n        // build datasource\n        DataSource dataSource = new DataSource();\n        Date now = new Date();\n\n        dataSource.setName(datasourceParam.getName().trim());\n        dataSource.setNote(datasourceParam.getNote());\n        dataSource.setUserId(loginUser.getId());\n        dataSource.setUserName(loginUser.getUserName());\n        dataSource.setType(datasourceParam.getType());\n        dataSource.setConnectionParams(JSONUtils.toJsonString(connectionParam));\n        dataSource.setCreateTime(now);\n        dataSource.setUpdateTime(now);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java#L78-L114","documentation":"During createDataSource, checkName(name) queries the datasource table for an existing record with the same name; if found, Status.DATASOURCE_EXIST (code 10015) is thrown because datasource names must be unique.","triggerScenarios":"POST /datasources whose 'name' matches an already-created datasource (checkName returns true before insert).","commonSituations":"Re-running an idempotent-looking setup script twice; clicking create twice in the UI; re-importing a workflow that references an existing datasource name.","solutions":["Pick a unique name (or suffix it with env/timestamp) before creating.","Query existing datasources first and reuse/update the existing entry instead of creating.","Delete or rename the conflicting datasource if it is stale."],"exampleFix":"// before\nparams.setName(\"mysql-prod\"); // already exists\n// after\nparams.setName(\"mysql-prod-\" + env); // or update the existing datasource","handlingStrategy":"validation","validationCode":"boolean nameTaken = api.getDatasourcesByName(name).size() > 0;\nif (nameTaken) { name = name + \"-\" + System.currentTimeMillis(); }","typeGuard":null,"tryCatchPattern":"try { ds = api.createDataSource(user, param); } catch (ServiceException e) { if (e.getCode() == 10015) { ds = findByName(param.getName()); } else throw e; }","preventionTips":["Make provisioning scripts idempotent (create-or-get)","Prefix names with environment/team to reduce collisions","Query existing datasources before creating"],"tags":["datasource","duplicate","uniqueness"],"backgroundTag":"file-already-exists","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"}