{"record":{"id":"550982c94c0dcf0a","repo":"apache/superset","slug":"column-not-found","errorCode":null,"errorMessage":"Column not found","messagePattern":"Column not found","errorType":"exception","errorClass":"ColumnNotFoundException","httpStatus":404,"severity":"error","filePath":"superset/connectors/sqla/models.py","lineNumber":2055,"sourceCode":"                else:\n                    qry = sa.select(sqla_column).where(sa.false()).select_from(tbl)\n                sql = self.database.compile_sqla_query(\n                    qry,\n                    catalog=self.catalog,\n                    schema=self.schema,\n                )\n                # A real DB/connectivity failure during the probe surfaces as a\n                # SupersetGenericDBErrorException from get_columns_description and\n                # is allowed to propagate unchanged; only a genuine empty result\n                # (the column truly isn't there) is a ColumnNotFoundException.\n                col_desc = get_columns_description(\n                    self.database,\n                    self.catalog,\n                    self.schema or None,\n                    sql,\n                )\n                if not col_desc:\n                    raise ColumnNotFoundException(message=\"Column not found\")\n                is_dttm = col_desc[0][\"is_dttm\"]  # type: ignore\n                # ResultSet already resolves the generic type from the\n                # driver's cursor.description; reuse it so callers can\n                # coerce filter values correctly (e.g. numeric IN-lists\n                # stay unquoted for numeric adhoc expressions like\n                # CAST(... AS BIGINT)).\n                generic_type = col_desc[0].get(\"type_generic\")\n\n        if is_dttm and has_timegrain:\n            sqla_column = self.db_engine_spec.get_timestamp_expr(\n                col=sqla_column,\n                pdf=pdf,\n                time_grain=time_grain,\n            )\n        return self.make_sqla_column_compatible(sqla_column, label), generic_type\n\n    def _get_series_orderby(\n        self,","sourceCodeStart":2037,"sourceCodeEnd":2073,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/connectors/sqla/models.py#L2037-L2073","documentation":"ColumnNotFoundException(\"Column not found\") raised in adhoc_column_to_sqla's probe path (models.py:2055). For adhoc columns, Superset probes the datasource with a SELECT of the expression and inspects the result columns; when get_columns_description returns an empty list — the expression yields no columns, i.e. the referenced column genuinely does not exist — this error is thrown. Real DB/connectivity failures propagate as SupersetGenericDBErrorException instead; only a true empty probe result maps here.","triggerScenarios":"Chart payload with an adhoc column referencing a column name not present in the (virtual) dataset, e.g. sqlExpression 'unknown_col' or a templated expression rendering to a name absent from the FROM subquery. The probe query SELECT unknown_col ... returns no column description, so the error is raised client-side of the engine.","commonSituations":"Dataset schema changed (column renamed/dropped) while charts still reference the old name; virtual datasets whose Jinja renders column names dynamically; mismatch between the physical table and cached dataset metadata after DDL.","solutions":["Verify the column exists in the dataset: refresh dataset metadata (dataset editor > Refresh) and confirm the column is listed.","Fix the adhoc column expression or chart to reference an existing column name.","If the underlying table changed, sync the dataset (re-save or force metadata refresh) so Superset's column list matches reality.","Catch ColumnNotFoundException when resolving dynamic column expressions so callers can present a field-mapping error."],"exampleFix":"// before (chart dimension)\n{ sqlExpression: 'usr_id' } // column was renamed to user_id\n\n// after\n{ sqlExpression: 'user_id' }","handlingStrategy":"try-catch","validationCode":"def column_exists_in_dataset(dataset, column_name: str) -> bool:\n    return any(c.column_name == column_name for c in dataset.columns)","typeGuard":null,"tryCatchPattern":"from superset.connectors.sqla.models import ColumnNotFoundException\n\ntry:\n    sqla_col, generic_type = table.adhoc_column_to_sqla(adhoc_col)\nexcept ColumnNotFoundException:\n    table = refresh_dataset_metadata(table)  # sync columns, then retry once\n    sqla_col, generic_type = table.adhoc_column_to_sqla(adhoc_col)","preventionTips":["Refresh dataset metadata after any DDL change on the source table.","Validate referenced column names against dataset.columns before running charts built dynamically.","Catch ColumnNotFoundException separately from generic DB errors — it means schema drift, not connectivity."],"tags":["adhoc-column","schema-drift","dataset","superset"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}