apache/dolphinscheduler · error · IllegalArgumentException

Get more than one datasource by name %s

Error message

Get more than one datasource by name %s

What it means

After filtering datasources matching the requested name and (optional) type, getDatasource requires a unique match; if more than one datasource shares the name (and type filter), it throws IllegalArgumentException because it cannot decide which one to return. DolphinScheduler historically allowed duplicate datasource names, so this is an ambiguity error, not a lookup failure.

Source

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

     */
    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);
        });
    }

    /**
     * Get workflow object by given workflow name. It returns map contain workflow id, name, code.
     * Useful in Python API create sub workflow task which need workflow information.
     *
     * @param userName     user who create or update schedule
     * @param projectName  project name which workflow belongs to
     * @param workflowName workflow name
     */
    public Map<String, Object> getWorkflowInfo(String userName, String projectName,

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Rename or delete the duplicate datasource in the Data Source center so the name is unique
  2. Pass the exact type (e.g. MYSQL) as the type argument so only one match remains
  3. Update pydolphinscheduler scripts to reference the uniquely renamed datasource
  4. Upgrade to a DolphinScheduler version enforcing datasource name uniqueness and deduplicate existing rows

Example fix

// before
dataSource ds = pythonGateway.getDatasource("my-db", null);
// after
dataSource ds = pythonGateway.getDatasource("my-db", "MYSQL");
Defensive patterns

Strategy: validation

Validate before calling

long count = dataSourceDao.queryDataSourceByName(name).stream()
    .filter(ds -> type == null || ds.getType().name().equalsIgnoreCase(type))
    .count();
if (count != 1) {
    throw new IllegalStateException("Expected exactly 1 datasource named " + name + ", found " + count);
}

Try / catch

try {
    DataSource ds = pythonGateway.getDatasource(name, type);
} catch (IllegalArgumentException e) {
    log.error("Ambiguous datasource name; pass an explicit type or deduplicate", e);
}

Prevention

When it happens

Trigger: Two or more datasources exist with the same name (optionally the type parameter passed to getDatasource is null or does not discriminate) and the Python gateway calls getDatasource(datasourceName, type).

Common situations: Datasource names duplicated across tenants/users; old DolphinScheduler instances where name uniqueness was not enforced; calling getDatasource without the type argument while same-named datasources of different types exist.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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