apache/dolphinscheduler · error · IllegalArgumentException

Can not find any datasource by name %s

Error message

Can not find any datasource by name %s

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java:491

        User user = usersService.queryUser(userName);
        usersService.deleteUserById(user, id);
        return usersService.queryUser(userName);
    }

    /**
     * Get single datasource by given datasource name. if type is not null,
     * it will return the datasource match the type.
     *
     * @param datasourceName datasource name of datasource
     * @param type           datasource type
     */
    public DataSource getDatasource(String datasourceName, String type) {

        List<DataSource> dataSourceList = dataSourceDao.queryDataSourceByName(datasourceName);
        if (dataSourceList == null || dataSourceList.isEmpty()) {
            String msg = String.format("Can not find any datasource by name %s", datasourceName);
            log.error(msg);
            throw new IllegalArgumentException(msg);
        }

        List<DataSource> dataSourceListMatchType = dataSourceList.stream()
                .filter(dataSource -> type == null || StringUtils.equalsIgnoreCase(dataSource.getType().name(), type))
                .collect(Collectors.toList());

        log.info("Get the datasource list match the type are: {}", dataSourceListMatchType);
        if (dataSourceListMatchType.size() > 1) {
            String msg = String.format("Get more than one datasource by name %s", datasourceName);
            log.error(msg);
            throw new IllegalArgumentException(msg);
        }

        return dataSourceListMatchType.stream().findFirst().orElseThrow(() -> {
            String msg = String.format("Can not find any datasource by name %s and type %s", datasourceName, type);
            log.error(msg);
            return new IllegalArgumentException(msg);
        });

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Verify the datasource exists in the web UI (Data Source center) with the exact name used in the Python script
  2. Create the missing datasource in DolphinScheduler before running the Python workflow
  3. Fix the datasourceName argument in the Python code to match the stored name exactly (trim whitespace)
  4. If names are ambiguous, use a more precise unique name

Example fix

// before (Python)
sql_task = Sql(..., datasource_name="prod-mysql")
// after
sql_task = Sql(..., datasource_name="prod-mysql-main")  # name verified in UI
Defensive patterns

Strategy: validation

Validate before calling

List<DataSource> existing = dataSourceDao.queryDataSourceByName(name);
if (existing == null || existing.isEmpty()) {
    throw new IllegalStateException("Datasource not found: " + name);
}

Try / catch

try {
    DataSource ds = pythonGateway.getDatasource(name, type);
} catch (IllegalArgumentException e) {
    log.error("Datasource missing, create it first: {}", e.getMessage());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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