getredash/redash · error · Exception

Failed getting schema

Error message

Failed getting schema

What it means

Raised by TreasureData.get_schema (redash/query_runner/treasuredata.py:90) as a bare re-raise when any exception occurs while listing databases/tables via the tdclient API during schema generation. The original exception is swallowed, so the message gives no root cause — typical causes are an invalid/expired API key, wrong endpoint, or network failure to api.treasuredata.com.

Source

Thrown at redash/query_runner/treasuredata.py:90

    def type(cls):
        return "treasuredata"

    def get_schema(self, get_stats=False):
        schema = {}
        if self.configuration.get("get_schema", False):
            try:
                with tdclient.Client(
                    self.configuration.get("apikey"), endpoint=self.configuration.get("endpoint")
                ) as client:
                    for table in client.tables(self.configuration.get("db")):
                        table_name = "{}.{}".format(self.configuration.get("db"), table.name)
                        for table_schema in table.schema:
                            schema[table_name] = {
                                "name": table_name,
                                "columns": [column[0] for column in table.schema],
                            }
            except Exception:
                raise Exception("Failed getting schema")
        return list(schema.values())

    def run_query(self, query, user):
        connection = tdclient.connect(
            endpoint=self.configuration.get("endpoint", "https://api.treasuredata.com"),
            apikey=self.configuration.get("apikey"),
            type=self.configuration.get("type", "hive").lower(),
            db=self.configuration.get("db"),
        )

        cursor = connection.cursor()
        try:
            cursor.execute(query)
            columns_tuples = [
                (i[0], TD_TYPES_MAPPING.get(i[1], None)) for i in cursor.show_job()["hive_result_schema"]
            ]
            columns = self.fetch_columns(columns_tuples)

View on GitHub (pinned to ca79fe988d)

Solutions

  1. Validate the apikey independently: `curl -H 'Authorization: TD1 <key>' https://api.treasuredata.com/v3/databases`
  2. Fix or re-paste the API key in the data source settings and run Test Connection
  3. Confirm the endpoint URL and network egress from the Redash worker to api.treasuredata.com
  4. Patch locally to log the original exception (raise ... from exc) so future failures name the root cause

Example fix

# before
except Exception:
    raise Exception("Failed getting schema")
# after (better diagnostics)
except Exception as exc:
    logger.exception('TreasureData schema fetch failed')
    raise Exception('Failed getting schema: {}'.format(exc))
Defensive patterns

Strategy: try-catch

Validate before calling

import requests
r = requests.get('https://api.treasuredata.com/v3/databases', headers={'Authorization': 'TD1 ' + apikey}, timeout=10)
r.raise_for_status()

Try / catch

try:
    schema = ds.query_runner.get_schema()
except Exception as e:
    logger.warning('TD schema failed: %s', e)
    schema = []

Prevention

When it happens

Trigger: Opening or refreshing the schema browser for a Treasure Data data source whose apikey is rejected, whose endpoint is misconfigured, or when the TD API is unreachable; any error inside the list_databases/list_tables iteration triggers this.

Common situations: Rotated or revoked TD API keys after the data source was configured; typo'd custom endpoint; outbound firewall blocking api.treasuredata.com; tdclient version incompatibility raising inside the loop.

Related errors


AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28). Data as JSON: /api/errors/b01afcc72103afd7. Report an issue: GitHub.