{"record":{"id":"8bdec667bff9d43f","repo":"apache/dolphinscheduler","slug":"can-not-find-any-datasource-by-name-s","errorCode":null,"errorMessage":"Can not find any datasource by name %s","messagePattern":"Can not find any datasource by name (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java","lineNumber":491,"sourceCode":"        User user = usersService.queryUser(userName);\n        usersService.deleteUserById(user, id);\n        return usersService.queryUser(userName);\n    }\n\n    /**\n     * Get single datasource by given datasource name. if type is not null,\n     * it will return the datasource match the type.\n     *\n     * @param datasourceName datasource name of datasource\n     * @param type           datasource type\n     */\n    public DataSource getDatasource(String datasourceName, String type) {\n\n        List<DataSource> dataSourceList = dataSourceDao.queryDataSourceByName(datasourceName);\n        if (dataSourceList == null || dataSourceList.isEmpty()) {\n            String msg = String.format(\"Can not find any datasource by name %s\", datasourceName);\n            log.error(msg);\n            throw new IllegalArgumentException(msg);\n        }\n\n        List<DataSource> dataSourceListMatchType = dataSourceList.stream()\n                .filter(dataSource -> type == null || StringUtils.equalsIgnoreCase(dataSource.getType().name(), type))\n                .collect(Collectors.toList());\n\n        log.info(\"Get the datasource list match the type are: {}\", dataSourceListMatchType);\n        if (dataSourceListMatchType.size() > 1) {\n            String msg = String.format(\"Get more than one datasource by name %s\", datasourceName);\n            log.error(msg);\n            throw new IllegalArgumentException(msg);\n        }\n\n        return dataSourceListMatchType.stream().findFirst().orElseThrow(() -> {\n            String msg = String.format(\"Can not find any datasource by name %s and type %s\", datasourceName, type);\n            log.error(msg);\n            return new IllegalArgumentException(msg);\n        });","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L473-L509","documentation":"PythonGateway.getDatasource looks up a datasource by name via dataSourceDao.queryDataSourceByName; if the DAO returns null or an empty list, it throws IllegalArgumentException with this message. The Python API layer requires exactly one matching datasource to build a task definition, so an empty lookup is treated as a hard failure.","triggerScenarios":"Calling the Python gateway API (pydolphinscheduler) with a datasource name that does not exist in this DolphinScheduler instance, or a name that was deleted/renamed between generating the Python workflow definition and executing getDatasource.","commonSituations":"pydolphinscheduler scripts referencing datasources created in a different environment (dev vs prod); datasource deleted by an admin; typo in the datasource name; datasource stored with different case/whitespace.","solutions":["Verify the datasource exists in the web UI (Data Source center) with the exact name used in the Python script","Create the missing datasource in DolphinScheduler before running the Python workflow","Fix the datasourceName argument in the Python code to match the stored name exactly (trim whitespace)","If names are ambiguous, use a more precise unique name"],"exampleFix":"// before (Python)\nsql_task = Sql(..., datasource_name=\"prod-mysql\")\n// after\nsql_task = Sql(..., datasource_name=\"prod-mysql-main\")  # name verified in UI","handlingStrategy":"validation","validationCode":"List<DataSource> existing = dataSourceDao.queryDataSourceByName(name);\nif (existing == null || existing.isEmpty()) {\n    throw new IllegalStateException(\"Datasource not found: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n    DataSource ds = pythonGateway.getDatasource(name, type);\n} catch (IllegalArgumentException e) {\n    log.error(\"Datasource missing, create it first: {}\", e.getMessage());\n}","preventionTips":["Keep datasource names unique and stable across environments","Validate datasource existence in pydolphinscheduler scripts before task creation","Avoid renaming datasources referenced by automation"],"tags":["python-api","datasource","not-found"],"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-14T05:17:10.506Z"}