{"record":{"id":"52f01bd2959a66be","repo":"getredash/redash","slug":"you-do-not-have-access-to-query-id-s","errorCode":null,"errorMessage":"You do not have access to query id %s.","messagePattern":"You do not have access to query id (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/python.py","lineNumber":278,"sourceCode":"\n    def get_query_result(self, query_id):\n        \"\"\"Get result of an existing query.\n\n        Parameters:\n        :query_id integer: ID of existing query\n        \"\"\"\n        user = self._get_current_user()\n\n        try:\n            query = models.Query.query.filter(\n                models.Query.id == query_id,\n                models.Query.org_id == user.org_id,\n            ).one()\n        except models.NoResultFound:\n            raise Exception(\"Query id %s does not exist.\" % query_id)\n\n        if query.data_source is None or not has_access(query.data_source, user, view_only):\n            raise Exception(\"You do not have access to query id %s.\" % query_id)\n\n        if query.latest_query_data is None:\n            raise Exception(\"Query does not have results yet.\")\n\n        if query.latest_query_data.data is None:\n            raise Exception(\"Query does not have results yet.\")\n\n        if query.latest_query_data.data_source is None or not has_access(\n            query.latest_query_data.data_source, user, view_only\n        ):\n            raise Exception(\"You do not have access to query id %s.\" % query_id)\n\n        return query.latest_query_data.data\n\n    def dataframe_to_result(self, result, df):\n        converted_result = pandas_to_result(df)\n\n        result[\"rows\"] = converted_result[\"rows\"]","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/python.py#L260-L296","documentation":"In get_query_result(), after the query is found, Redash checks query.data_source is not None and has_access(query.data_source, user, view_only). Failure raises this Exception: the query exists but its data source was removed, or the current user lacks (view-only) access to it.","triggerScenarios":"Calling get_query_result() on a query whose data source was deleted (data_source is None), or whose data source is restricted to groups the current user doesn't belong to.","commonSituations":"Query orphaned after its data source was deleted; sharing Python queries with users who can see the query but not its underlying data source.","solutions":["Have an admin reattach/restore the query's data source","Grant the user's group view access to the query's data source","Use a different query backed by an accessible data source"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"q = load_query(qid, org)\nassert q.data_source is not None and has_access(q.data_source, user, view_only=True)","typeGuard":null,"tryCatchPattern":"try:\n    get_query_result(qid)\nexcept Exception as e:\n    if 'You do not have access to query id' in str(e):\n        request_access(q.data_source); raise","preventionTips":["When sharing queries, also share/permit their underlying data sources","Delete or reattach queries when removing a data source"],"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"}