{"record":{"id":"37423d8ac9388610","repo":"getredash/redash","slug":"you-do-not-have-access-to-data-source-s","errorCode":null,"errorMessage":"You do not have access to data source: %s.","messagePattern":"You do not have access to data source: (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/python.py","lineNumber":226,"sourceCode":"        if \"rows\" not in result:\n            result[\"rows\"] = []\n\n        result[\"rows\"].append(values)\n\n    def _get_data_source(self, data_source_name_or_id, access_level):\n        user = self._get_current_user()\n\n        try:\n            data_sources = models.DataSource.query.filter(models.DataSource.org_id == user.org_id)\n            if isinstance(data_source_name_or_id, int):\n                data_source = data_sources.filter(models.DataSource.id == data_source_name_or_id).one()\n            else:\n                data_source = data_sources.filter(models.DataSource.name == data_source_name_or_id).one()\n        except (models.NoResultFound, MultipleResultsFound):\n            raise Exception(\"Wrong data source name/id: %s.\" % data_source_name_or_id)\n\n        if not has_access(data_source, user, access_level):\n            raise Exception(\"You do not have access to data source: %s.\" % data_source_name_or_id)\n\n        return data_source\n\n    def execute_query(self, data_source_name_or_id, query, result_type=None):\n        \"\"\"Run query from specific data source.\n\n        Parameters:\n        :data_source_name_or_id string|integer: Name or ID of the data source\n        :query string: Query to run\n        \"\"\"\n        data_source = self._get_data_source(data_source_name_or_id, not_view_only)\n\n        data, error = data_source.query_runner.run_query(query, self._current_user)\n        if error is not None:\n            raise Exception(error)\n\n        # TODO: allow avoiding the JSON dumps/loads in same process\n        query_result = data","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/python.py#L208-L244","documentation":"After resolving a data source, _get_data_source() checks has_access(data_source, user, access_level) against the current user's group permissions. Failure raises this Exception — the data source exists but the user executing the Python query isn't in a group with the required access level (view or edit).","triggerScenarios":"Calling execute_query() from a Python query on a data source where the current user only has view-only access but edit-level is requested, or has no group membership granting access at all.","commonSituations":"The Python query runs as the querying user (not the query author), so sharing a query with users lacking data source access fails; data source moved to a restricted group after the query was created.","solutions":["Add the user (or their group) to a data source group with sufficient permission in data source settings","If only viewing is needed, ensure the code path requests view-only access","Switch to a data source the user can access, or have an admin duplicate the query under proper permissions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from redash.permissions import has_access\nds = resolve_data_source(ref, org)\nassert ds is not None and has_access(ds, user, access_level), 'user lacks data source access'","typeGuard":null,"tryCatchPattern":"try:\n    execute_query(ref, q)\nexcept Exception as e:\n    if 'You do not have access to data source' in str(e):\n        raise UserVisibleError('Request access to data source %s' % ref)","preventionTips":["Grant viewer group access before sharing queries that read that source","Test shared queries under a low-privilege user account"],"tags":["redash","python-runner","permissions","authorization"],"backgroundTag":"permission-denied-data-source","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}