apache/dolphinscheduler · error · ServiceException
QUERY_DATASOURCE_ERROR
QUERY_DATASOURCE_ERROR
Error message
Status.QUERY_DATASOURCE_ERROR
What it means
getTables throws QUERY_DATASOURCE_ERROR when dataSourceDao.queryById(datasourceId) returns null, meaning no datasource row exists for the supplied id. It is a lookup failure raised before permission and connection logic runs.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java:355
}
return resultList.stream().map(DataSourceSimpleInfoVO::new).collect(Collectors.toList());
}
@Override
public List<DataSourceSimpleInfoVO> authedDatasource(User loginUser, Integer userId) {
if (isNotAdmin(loginUser)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
List<DataSource> authedDatasourceList = dataSourceDao.queryAuthedDatasource(userId);
return authedDatasourceList.stream().map(DataSourceSimpleInfoVO::new).collect(Collectors.toList());
}
@Override
public List<ParamsOptions> getTables(User loginUser, Integer datasourceId, String database) {
DataSource dataSource = dataSourceDao.queryById(datasourceId);
if (dataSource == null) {
throw new ServiceException(Status.QUERY_DATASOURCE_ERROR);
}
if (!canOperatorPermissions(loginUser, new Object[]{datasourceId}, AuthorizationType.DATASOURCE,
ApiFuncIdentificationConstant.DATASOURCE)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
List<String> tableList;
BaseConnectionParam connectionParam =
(BaseConnectionParam) DataSourceUtils.buildConnectionParams(
dataSource.getType(),
dataSource.getConnectionParams());
if (null == connectionParam) {
throw new ServiceException(Status.DATASOURCE_CONNECT_FAILED);
}
Connection connection =View on GitHub (pinned to 02eac45a1b)
Solutions
- Verify the datasourceId exists (GET /datasources/list) and use a valid id
- Re-select the datasource from the UI to refresh stale client state
- If recently deleted, recreate the datasource and retry
- Return the id in error handling so callers can distinguish bad-id from connect failure
Example fix
// before
List<ParamsOptions> tables = dataSourceService.getTables(user, id, db); // id may be stale
// after
DataSource ds = ...; // resolve/refresh id first
if (ds == null) { throw ...; } // caller-side guard: only call getTables with a fresh id
List<ParamsOptions> tables = dataSourceService.getTables(user, ds.getId(), db); Defensive patterns
Strategy: validation
Validate before calling
DataSource ds = dataSourceDao.queryById(datasourceId);
if (ds == null) { throw new IllegalArgumentException("datasource " + datasourceId + " not found"); } Try / catch
try {
return dataSourceService.getTables(loginUser, datasourceId, database);
} catch (ServiceException e) {
if (Status.QUERY_DATASOURCE_ERROR.getCode() == e.getCode()) { /* refresh datasource list, prompt re-selection */ }
throw e;
} Prevention
- Resolve datasource ids by name at call time rather than caching ids
- Refresh the datasource list after any admin deletes resources
- Validate datasourceId against the user's visible list before calling
When it happens
Trigger: Calling the get-tables API (list tables of a datasource/database) with a datasourceId that does not exist in t_ds_datasource, or one that was deleted between listing and querying.
Common situations: Stale UI holding a datasource that an admin deleted; copy-pasted or guessed datasourceId in scripts/curl calls; cross-tenant id confusion where the id exists but is not visible; datasource import/export mismatches.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Can not find any datasource by name %s
- 20004
- RESOURCE_NOT_EXIST
- QUERY_ENVIRONMENT_BY_CODE_ERROR
- QUERY_ENVIRONMENT_BY_NAME_ERROR
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/e806930f89b37d15.
Report an issue: GitHub.