"Sync columns from source" fails on ClickHouse tables with ALIAS, MATERIALIZED or DEFAULT columns
Bug description
In the dataset editor, Sync columns from source fails on any ClickHouse table with an ALIAS, MATERIALIZED, DEFAULT or TTL column. Instead of syncing, it shows Unserializable object price * qty of type <class 'sqlalchemy.sql.elements.TextClause'>, so new or changed columns on those tables can't be picked up from the UI.
Cause. Since clickhouse-connect 1.1.0, the dialect's get_columns returns those expressions as SQLAlchemy text() clauses (clickhouse_alias, clickhouse_materialized, server_default, clickhouse_ttl). convert_inspector_columns copies every inspector key, and /datasource/external_metadata_by_name/ returns the list through json_response, which can't encode a clause.
How to reproduce (ClickHouse 25.3, clickhouse-connect 1.11.0, the latest release)
CREATE TABLE t (ts DateTime, price Float64, qty UInt32, total Float64 ALIAS price * qty) ENGINE = MergeTree ORDER BY ts;
- Add
tas a dataset (this works). - Edit the dataset, open the Columns tab and click Sync columns from source.
- An error toast appears, and the endpoint returns
500 {"error": "Unserializable object price * qty of type <class 'sqlalchemy.sql.elements.TextClause'>"}.
day Date MATERIALIZED toDate(ts), note String DEFAULT 'x' and note String TTL ts + INTERVAL 30 DAY fail the same way. Tables without such columns sync fine.
Proposal. In convert_inspector_columns, turn SQLAlchemy ClauseElement values into their SQL string ("clickhouse_alias": "price * qty"). The editor only reads column_name, type and is_dttm from the result, so nothing else changes. PR to follow.
Screenshots/recordings
On 7.0.0rc2, after adding a column with ALTER TABLE t ADD COLUMN discount Float64 ALIAS price * 0.1: the sync shows the error toast and the new column is not added (Columns 4).
Superset version
master / latest-dev
Python version
3.11
Node version
Not applicable
Browser
Not applicable
Additional context
- Versions: the latest clickhouse-connect and every release since 1.1.0. The documented Docker install (
echo "clickhouse-connect>=0.13.0" >> ./docker/requirements-local.txt) pulls the latest, 1.11.0, on 6.1 and 7.0 alike. Only 6.1'sapache-superset[clickhouse]extra (<1.0) avoids it; since #40944, 7.0's extra requires>=1.7.2and CI runs 1.7.2, so on 7.0 every route hits it. - Workaround:
PUT /api/v1/dataset/<id>/refreshrefreshes the columns from the source and works. - cc @joe-clickhouse, @hughhhh (#24248), @rusackas (#40944)
Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.