{"record":{"id":"d655a4e85177cc80","repo":"apache/dolphinscheduler","slug":"resource-not-exist-or-no-permission","errorCode":"RESOURCE_NOT_EXIST_OR_NO_PERMISSION","errorMessage":"User does not have permission to use datasource referenced by task, userId:{}.","messagePattern":"User does not have permission to use datasource referenced by task, userId:(.+?)\\.","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/TaskDatasourcePermissionChecker.java","lineNumber":82,"sourceCode":"            Map<Integer, AbstractResourceParameters> datasourceResources =\n                    resources.getResourceMap(ResourceType.DATASOURCE);\n            if (datasourceResources == null) {\n                continue;\n            }\n            datasourceResources.keySet().stream()\n                    .filter(datasourceId -> datasourceId != null && datasourceId > 0)\n                    .forEach(datasourceIds::add);\n        }\n\n        if (datasourceIds.isEmpty()) {\n            return;\n        }\n\n        int userId = loginUser.getUserType() == UserType.ADMIN_USER ? 0 : loginUser.getId();\n        Integer[] datasourceIdArray = datasourceIds.toArray(new Integer[0]);\n        if (!resourcePermissionCheckService.resourcePermissionCheck(\n                AuthorizationType.DATASOURCE, datasourceIdArray, userId, log)) {\n            log.warn(\"User does not have permission to use datasource referenced by task, userId:{}.\",\n                    loginUser.getId());\n            throw new ServiceException(Status.RESOURCE_NOT_EXIST_OR_NO_PERMISSION);\n        }\n    }\n}\n","sourceCodeStart":64,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/TaskDatasourcePermissionChecker.java#L64-L88","documentation":"TaskDatasourcePermissionChecker.checkPermission throws ServiceException(RESOURCE_NOT_EXIST_OR_NO_PERMISSION) when the current user fails resourcePermissionCheck for the datasource IDs referenced by a task. Non-admins are checked against their own userId; the API rejects the task save/execution request.","triggerScenarios":"A non-admin user saves or operates on a task whose datasourceIds include at least one datasource they have no DATASOURCE authorization for; resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, ...) returns false.","commonSituations":"Task inherited/copied from another user's workflow, datasource deleted or reassigned, user role downgraded, datasource created by admin without granting access to the project member, cross-project task references.","solutions":["Have an admin grant the user authorization for the referenced datasource (Datasource permission management / authorization page).","Reassign the task to use a datasource the user already has permission on.","Check that the datasource still exists — it may have been deleted, triggering the same no-permission status.","If appropriate, perform the operation as an admin user (admins bypass the per-user check with userId 0)."],"exampleFix":"// before\n// user 'dev1' references datasource id=42 owned by admin, no grant\nPOST /datasources/... task uses datasourceId=42 -> 429/RESOURCE_NOT_EXIST_OR_NO_PERMISSION\n// after\n// admin grants dev1 access to datasource 42 (UI: Security -> Datasource -> authorize) or dev1 picks own datasource id=43","handlingStrategy":"validation","validationCode":"// before saving a task, verify user's datasource access\nGET /api/dolphinscheduler/datasources/list?searchVal=\nowned_ids = {ds['id'] for ds in response['data']}\nassert datasource_ids <= owned_ids, f\"no permission on: {datasource_ids - owned_ids}\"","typeGuard":"def has_datasource_permission(user_datasource_ids, required_ids):\n    return set(required_ids).issubset(set(user_datasource_ids))","tryCatchPattern":"try:\n    api.save_task(...)\nexcept ApiException as e:\n    if 'RESOURCE_NOT_EXIST_OR_NO_PERMISSION' in str(e):\n        request_datasource_grant(); raise","preventionTips":["Grant datasource permissions to project members when creating shared workflows","Verify datasource ownership after copying workflows between projects/users","Re-check permissions after role downgrades","Confirm referenced datasources still exist before saving tasks"],"tags":["permissions","datasource","authorization","api"],"backgroundTag":"permission-denied","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"}