getredash/redash · error · Exception
Failed to get schema: {str(e)}
Error message
Failed to get schema: {str(e)} What it means
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.
Source
Thrown at redash/query_runner/d1.py:141
# Get all tables from sqlite_master
tables = self._query(
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_KV'"
)
for table in tables:
table_name = table["name"]
# Get column information for each table
columns = self._query(f"PRAGMA table_info({table_name})")
# Extract detailed column information including data types
column_info = []
for col in columns:
column_info.append({"name": col["name"], "type": col["type"]})
schema.append({"name": table_name, "columns": column_info})
except Exception as e:
raise Exception(f"Failed to get schema: {str(e)}")
return schema
def test_connection(self):
query = "SELECT 1 as test"
_, error = self.run_query(query, None)
if error:
raise Exception(error)
register(D1QueryRunner)
View on GitHub (pinned to ca79fe988d)
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
Defensive patterns
Strategy: fallback
Validate before calling
_, err = d1_runner.run_query('SELECT 1', None)
assert err is None, f'fix base connectivity first: {err}' Try / catch
try:
schema = d1_runner.get_schema()
except Exception as e:
if str(e).startswith('Failed to get schema:'):
log(inner_error := str(e).split(':', 1)[1]); schema = [] # degrade gracefully Prevention
- 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
When it happens
Trigger: 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.
Common situations: Expired API token discovered only during schema refresh, renamed/deleted database, or transient Cloudflare API failures.
Related errors
- Error during query execution. Reason: {error}
- Failed to connect to Cloudflare D1: {str(e)}
- Invalid JSON response from D1: {str(e)}
- Unexpected response format from D1: {str(e)}
- Failed to get tables: {error}
AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28).
Data as JSON: /api/errors/2ce2745cf4aeb1da.
Report an issue: GitHub.