{"record":{"id":"2ce2745cf4aeb1da","repo":"getredash/redash","slug":"failed-to-get-schema-str-e","errorCode":null,"errorMessage":"Failed to get schema: {str(e)}","messagePattern":"Failed to get schema: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/d1.py","lineNumber":141,"sourceCode":"            # Get all tables from sqlite_master\n            tables = self._query(\n                \"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_KV'\"\n            )\n\n            for table in tables:\n                table_name = table[\"name\"]\n                # Get column information for each table\n                columns = self._query(f\"PRAGMA table_info({table_name})\")\n\n                # Extract detailed column information including data types\n                column_info = []\n                for col in columns:\n                    column_info.append({\"name\": col[\"name\"], \"type\": col[\"type\"]})\n\n                schema.append({\"name\": table_name, \"columns\": column_info})\n\n        except Exception as e:\n            raise Exception(f\"Failed to get schema: {str(e)}\")\n\n        return schema\n\n    def test_connection(self):\n        query = \"SELECT 1 as test\"\n        _, error = self.run_query(query, None)\n        if error:\n            raise Exception(error)\n\n\nregister(D1QueryRunner)\n","sourceCodeStart":123,"sourceCodeEnd":153,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/d1.py#L123-L153","documentation":"D1 runner's get_schema wraps its schema-building loop; any exception while listing tables or reading per-table column info is re-raised prefixed 'Failed to get schema: '. Usually the inner error is one of errors [12]-[14] bubbling up from _query during introspection.","triggerScenarios":"Clicking 'Refresh schema' or opening the schema panel for a D1 source when the introspection queries (table list or column info) fail with a connection, auth, or parse error inside _query.","commonSituations":"Expired API token discovered only during schema refresh, renamed/deleted database, or transient Cloudflare API failures.","solutions":["Read the suffix of the message — it contains the underlying _query error; fix that first (token, IDs, network)","Use test_connection (SELECT 1) to verify basic connectivity before refreshing schema","Confirm the token's account scope covers every database being introspected","Retry after fixing the inner error; the wrapper itself needs no separate action"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"_, err = d1_runner.run_query('SELECT 1', None)\nassert err is None, f'fix base connectivity first: {err}'","typeGuard":null,"tryCatchPattern":"try:\n    schema = d1_runner.get_schema()\nexcept Exception as e:\n    if str(e).startswith('Failed to get schema:'):\n        log(inner_error := str(e).split(':', 1)[1]); schema = []  # degrade gracefully","preventionTips":["Run test_connection before schema refresh in automation","Treat the inner errors (12-14) as the root cause; the wrapper adds no new information","Cache the last-good schema to survive transient API failures"],"tags":["redash","cloudflare-d1","schema"],"backgroundTag":"schema-introspection-failed","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}