{"record":{"id":"e806930f89b37d15","repo":"apache/dolphinscheduler","slug":"query-datasource-error","errorCode":"QUERY_DATASOURCE_ERROR","errorMessage":"Status.QUERY_DATASOURCE_ERROR","messagePattern":"Status\\.QUERY_DATASOURCE_ERROR","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java","lineNumber":355,"sourceCode":"        }\n        return resultList.stream().map(DataSourceSimpleInfoVO::new).collect(Collectors.toList());\n    }\n\n    @Override\n    public List<DataSourceSimpleInfoVO> authedDatasource(User loginUser, Integer userId) {\n        if (isNotAdmin(loginUser)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n        List<DataSource> authedDatasourceList = dataSourceDao.queryAuthedDatasource(userId);\n        return authedDatasourceList.stream().map(DataSourceSimpleInfoVO::new).collect(Collectors.toList());\n    }\n\n    @Override\n    public List<ParamsOptions> getTables(User loginUser, Integer datasourceId, String database) {\n        DataSource dataSource = dataSourceDao.queryById(datasourceId);\n\n        if (dataSource == null) {\n            throw new ServiceException(Status.QUERY_DATASOURCE_ERROR);\n        }\n\n        if (!canOperatorPermissions(loginUser, new Object[]{datasourceId}, AuthorizationType.DATASOURCE,\n                ApiFuncIdentificationConstant.DATASOURCE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        List<String> tableList;\n        BaseConnectionParam connectionParam =\n                (BaseConnectionParam) DataSourceUtils.buildConnectionParams(\n                        dataSource.getType(),\n                        dataSource.getConnectionParams());\n\n        if (null == connectionParam) {\n            throw new ServiceException(Status.DATASOURCE_CONNECT_FAILED);\n        }\n\n        Connection connection =","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java#L337-L373","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nList<ParamsOptions> tables = dataSourceService.getTables(user, id, db); // id may be stale\n// after\nDataSource ds = ...; // resolve/refresh id first\nif (ds == null) { throw ...; } // caller-side guard: only call getTables with a fresh id\nList<ParamsOptions> tables = dataSourceService.getTables(user, ds.getId(), db);","handlingStrategy":"validation","validationCode":"DataSource ds = dataSourceDao.queryById(datasourceId);\nif (ds == null) { throw new IllegalArgumentException(\"datasource \" + datasourceId + \" not found\"); }","typeGuard":null,"tryCatchPattern":"try {\n    return dataSourceService.getTables(loginUser, datasourceId, database);\n} catch (ServiceException e) {\n    if (Status.QUERY_DATASOURCE_ERROR.getCode() == e.getCode()) { /* refresh datasource list, prompt re-selection */ }\n    throw e;\n}","preventionTips":["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"],"tags":["datasource","not-found","lookup"],"backgroundTag":"entity-not-found","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"}