bmuraykhi opened a new issue, #45960:
URL: https://github.com/apache/superset/issues/45960

   ### Bug description
   
   ### 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)
   
   ```sql
   CREATE TABLE t (ts DateTime, price Float64, qty UInt32, total Float64 ALIAS 
price * qty) ENGINE = MergeTree ORDER BY ts;
   ```
   
   1. Add `t` as a dataset (this works).
   2. Edit the dataset, open the Columns tab and click **Sync columns from 
source**.
   3. 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).
   
   <img width="3504" height="3960" alt="Image" 
src="https://github.com/user-attachments/assets/036cae22-a848-4ef9-ae9b-15ac015224c7";
 />
   
   ### 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's `apache-superset[clickhouse]` extra (`<1.0`) avoids it; since 
#40944, 7.0's extra requires `>=1.7.2` and CI runs 1.7.2, so on 7.0 every route 
hits it.
   - Workaround: `PUT /api/v1/dataset/<id>/refresh` refreshes 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to