Skip to content

feat(clickhouse): migrate legacy clickhouse connections to clickhouse-connect - #44283

Open
eschutho wants to merge 10 commits into
masterfrom
sc-120997-clickhouse-legacy-migration
Open

eschutho wants to merge 10 commits into
masterfrom
sc-120997-clickhouse-legacy-migration

Conversation

@eschutho

@eschutho eschutho commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Part of epic sc-120993 (migrate DB connections to the new dynamic connection form). Story: https://app.shortcut.com/preset/story/120997

Superset ships two ClickHouse engine specs:

  • ClickHouseEngineSpec: backend key clickhouse, the clickhouse-sqlalchemy driver. Legacy, with no parameters_schema, so its connections still render the free-form SQLAlchemy URI editor.
  • ClickHouseConnectEngineSpec: backend key clickhousedb, default driver connect (clickhouse-connect). Defines parameters_schema and renders the new dynamic connection form.

The engine spec is picked from the URI's backend name, so this data migration rewrites saved legacy clickhouse[+driver]:// URIs to clickhousedb+connect://. A row is rewritten only when its meaning carries over exactly. Every other row stays on the legacy driver, which keeps working, and its id is logged during superset db upgrade so an operator can migrate it by hand.

The migration chains off master's single head b8f3a2c91d64.

Scheme / port / TLS mapping

The legacy HTTP dialect builds f"{protocol}://{host}:{url.port or 8123}/{endpoint}". TLS comes only from ?protocol=https, the port defaults to 8123 whatever the protocol, and secure is never read. clickhouse-connect reads secure and defaults TLS connections to 8443.

Legacy Rewritten to Notes
clickhouse://, clickhouse+http:// clickhousedb+connect:// Port kept. protocol=https becomes secure=true, and 8123 is pinned if no port was set. protocol=http and stray secure are dropped. verify=true|false is kept.
clickhouse+native://, clickhouse+asynch:// clickhousedb+connect:// clickhouse-connect is HTTP-only, so 9000 (or no port) becomes 8123. A falsy secure is dropped.

Left on the legacy driver (logged by id): any other URI parameter, since the drivers don't share a vocabulary (the legacy endpoint is the HTTP path; clickhouse-connect forwards unknown keys as server settings and rejects ones it doesn't recognize); a CA-path verify; a non-default native port; native TLS (secure=true); a rewritten URI that would overflow the 1024-character column; and any non-empty extra.engine_params.connect_args (or an extra that cannot be parsed). Both drivers receive connect_args as keyword arguments, but clickhouse-connect sends unknown keys such as timeout to the server as settings and coerces a CA-bundle path in verify to False, which would silently disable certificate verification.

Converted rows also get configuration_method = 'dynamic_form', so the edit modal opens the new form instead of the SQLAlchemy URI editor.

Credentials live in the separately encrypted password column, and the URI only carries the masked placeholder. The migration never reads or writes password or encrypted_extra.

DISALLOWED_SQL_FUNCTIONS gains a clickhousedb entry equal to clickhouse. That lookup is keyed by engine, so without the entry, converted connections (and connections created directly on clickhousedb) bypassed the ClickHouse function denylist. A unit test runs Database.execute on a clickhousedb connection against the unpatched default config, asserting that SELECT version() is rejected and SELECT 1 runs, so dropping that entry fails CI.

Engine specs gain time_grain_addon_aliases, and ClickHouseConnectEngineSpec declares ("clickhouse",). TIME_GRAIN_ADDON_EXPRESSIONS entries configured under clickhouse therefore keep resolving for converted connections, with clickhousedb entries taking precedence. The alias applies in both get_time_grain_expressions and the partition-mirroring bucket-width check.

Rollback

upgrade records each converted row's original URI, its original configuration_method, and a fingerprint of its migrated state in a migration-owned table, clickhouse_uri_migration. downgrade restores both only for rows whose fingerprint still matches, then drops the table. Connections edited after the upgrade, and connections created directly on clickhousedb, are left untouched. This follows the in-tree Databricks URI migration (b8f3a2c91d64). upgrade is idempotent.

TESTING INSTRUCTIONS

  • pytest tests/unit_tests/migrations/test_migrate_clickhouse_to_clickhousedb.py runs 49 cases against real Alembic operations: HTTP/native/TLS mapping, port pinning, skipped rows and their warnings, idempotency, an exact round trip, a downgrade that leaves edited or native rows alone, configuration_method switching and restoring, and rows skipped for connect_args.
  • A real flask db upgrade → downgrade b8f3a2c91d64 → upgrade cycle on SQLite, seeded with legacy rows, restored the original URIs and configuration_method byte-for-byte, and left a connect_args row on the legacy driver with a warning.
  • superset db heads prints a single head.
  • Manually: save a clickhouse://user:pass@host:8123/db connection, run superset db upgrade, then edit the connection. It now renders the dynamic ClickHouse form.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Runtime: keyset-batched updates over dbs rows whose URI starts with clickhouse (about 30 rows across the fleet). Runtime is negligible and there is no downtime. Documented in UPDATING.md.

🤖 Generated with Claude Code

@bito-code-review

bito-code-review Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #bcf184

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py - 1
    • CWE-319: TLS Downgrade · Line 172-172
      Legacy `clickhouse-sqlalchemy` selects HTTPS via `?protocol=https` (its `create_connect_args` builds `'%s://...' % protocol`). `clickhouse-connect`'s `_parse_connection_params` derives TLS only from `secure`/`interface`/`port` and ignores `protocol`, so a migrated `clickhousedb+connect://...?protocol=https` silently connects over plain HTTP on 8123 — a TLS downgrade that can also fail against TLS-only servers. Map `protocol=https` to `secure=true` instead of preserving it. ([CWE-319](https://cwe.mitre.org/data/definitions/319.html))
Review Details
  • Files reviewed - 2 · Commit Range: d8899a6..d8899a6
    • superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py
    • tests/unit_tests/migrations/test_migrate_clickhouse_to_clickhousedb.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added risk:db-migration PRs that require a DB migration preset-io labels Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.98%. Comparing base (1ac8ffb) to head (e906ddf).

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #44283       +/-   ##
===========================================
+ Coverage   56.66%   85.98%   +29.31%     
===========================================
  Files        3130     3126        -4     
  Lines      217962   217622      -340     
  Branches    51682    51526      -156     
===========================================
+ Hits       123511   187112    +63601     
+ Misses      93255    27088    -66167     
- Partials     1196     3422     +2226     
Flag Coverage Δ
hive 33.80% <36.84%> (+<0.01%) ⬆️
mysql 51.62% <94.73%> (?)
postgres 51.65% <94.73%> (?)
presto 35.50% <36.84%> (+<0.01%) ⬆️
python 88.51% <100.00%> (+52.92%) ⬆️
sqlite 51.32% <94.73%> (?)
unit 84.03% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

"""
# Credentials are not escaped for "@", so the host section starts after the
# last one.
host_start = remainder.rfind("@") + 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: rfind("@") scans query and path text too, so an @ after the authority changes the detected host start and corrupts the rewritten URI. [logic error]

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py
**Line:** 123:123
**Comment:**
	*Logic Error: `rfind("@")` scans query and path text too, so an `@` after the authority changes the detected host start and corrupts the rewritten URI.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 1218d9d.

The code finds the authority boundary at the first / or ?, then searches for @ only within that authority. Path or query text can no longer affect the credential separator.

If that's not right, unresolve this thread and CodeAnt will leave it open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 0f0043b.

The code finds the authority boundary at the first / or ?, then searches for @ only within that authority.

If that's not right, unresolve this thread and CodeAnt will leave it open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 0eae123.

The code finds the authority boundary at the first / or ?, then searches for @ only within that authority.

If that's not right, unresolve this thread and CodeAnt will leave it open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of eba10e7.

The parser now finds the authority boundary at the first / or ? and searches for @ only within that authority.

If that's not right, unresolve this thread and CodeAnt will leave it open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 0127f20.

The parser now finds the authority boundary at the first / or ? and searches for @ only within that authority.

If that's not right, unresolve this thread and CodeAnt will leave it open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 6b9ef67.

The parser now finds the authority boundary at the first / or ? and searches for @ only within that authority.

If that's not right, unresolve this thread and CodeAnt will leave it open.

for database in paginated_update(query):
updated = _migrate_uri(database.sqlalchemy_uri)
if updated:
database.sqlalchemy_uri = updated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The rewritten scheme and possibly port add characters to the URI, so rows already at the dbs.sqlalchemy_uri 1024-character limit can fail or be truncated. [type error]

Assessment: 🟠 Major · 🔁 Occurrence: Rarely

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py
**Line:** 185:185
**Comment:**
	*Type Error: The rewritten scheme and possibly port add characters to the URI, so rows already at the `dbs.sqlalchemy_uri` 1024-character limit can fail or be truncated.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 1218d9d.

The migration checks the rewritten URI against the 1024-character column limit and skips the update with a warning when it would exceed that limit.

If that's not right, unresolve this thread and CodeAnt will leave it open.

@aminghadersohi

Copy link
Copy Markdown
Contributor

I reproduced the master migration conflict at ae240a8e6f0332acb709943d0884eae73927c9de: c7f53d184ea2 and 88a01c781622. This PR already joins those exact heads, so it overlaps the baseline repair being investigated for the startup/integration failures on #44285, #44286 and #44287.

@eschutho Would you be comfortable separating the baseline repair into a minimal no-op merge revision, with this migration then rebased/reparented to that revision? That would unblock master without coupling the repair to the ClickHouse data rewrite. Neither migration should land unchanged alongside an independent merge of the same parents: that would leave two heads again. No changes have been made to this PR or the driver PRs.

@aminghadersohi

Copy link
Copy Markdown
Contributor

The standalone no-op baseline repair is now ready for review as #44288, revision e2f3a1b9c640. It preserves existing migration ancestry and has passed graph/SQLite transition validation plus independent review. Please coordinate landing order: if #44288 lands first, rebase/reparent f7b3a9c14e02 onto e2f3a1b9c640; if this PR lands first, #44288 must be dropped/reassessed. No changes have been made to this PR, and no consent or merge is assumed.

@aminghadersohi

aminghadersohi commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Coordination update for @eschutho: @mikebridge has selected #44288, and duplicate #44317 is CLOSED without merging.

#44288 remains the fully green standalone baseline repair (13/13 required checks SUCCESS), awaiting your requested maintainer review. After #44288 lands, please rebase/reparent this migration onto e2f3a1b9c640 rather than the two original parents. This avoids recreating multiple heads. Please confirm that ordering; no consent is assumed from the selection by another PR author.

Owners of #44284–#44287 are awaiting actual repaired master before rebasing/rerunning all applicable checks. The landing watch will notify them only after verifying the merged repair is on master with a single head. No merge, draft conversion, or code changes to this PR are being made by this session.

@netlify

netlify Bot commented Sep 15, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit aa58f1e
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aa9931f214c320008bd2e4e
😎 Deploy Preview https://deploy-preview-44283--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One migration-graph note below — flagging only the parent pointer; I have not reviewed the ClickHouse migration itself, so this is a comment rather than an approval.


# revision identifiers, used by Alembic.
revision = "f7b3a9c14e02"
down_revision = ("88a01c781622", "c7f53d184ea2")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#44288 landed (4c27cbd007) and consumed both of these parents into e2f3a1b9c640, so master is single-headed again. As written this migration takes the same two parents, which makes it a second childless head — re-forking the graph the moment it merges.

Suggested change
down_revision = ("88a01c781622", "c7f53d184ea2")
down_revision = "e2f3a1b9c640"

Worth knowing for anyone tracking the earlier CI breakage: enforce-single-migration-head will catch this here because this PR touches superset/migrations/, but the two-head state is invisible to every PR that does not — it surfaces instead as docker-build (dev) failing on flask db upgrade, which cascades into the whole integration matrix.

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posting on Mike Bridge's behalf — this is their PR reviewer agent. Forward any pushback to them and they'll loop me back in.

Ran six review lenses over this across two different models (four locally, two in a separate Codex session with no shared context). Four things below look worth addressing before merge; I've left out the cosmetic notes. All line numbers verified against aa58f1e8. Separate from my earlier comment about the down_revision parent, which still applies.


superset/config.py:2328 (not in this diff)

DISALLOWED_SQL_FUNCTIONS is keyed by db_engine_spec.engine and read as .get(engine, set()) in three places — superset/sql_lab.py:481, superset/models/helpers.py:2283, superset/commands/sql_lab/estimate.py:107. The dict has a clickhouse key but no clickhousedb one, and ClickHouseConnectEngineSpec.engine = "clickhousedb" (superset/db_engine_specs/clickhouse.py:387). So every row this migration rewrites moves to a key with no entry, and the denylist falls back to the empty set — un-blocking currentUser, hostName, getOSInformation, getSetting, url and filesystemPath at all three gates.

Would it be worth adding the key in this PR, so the guard travels with the rows?

    "clickhousedb": DISALLOWED_SQL_FUNCTIONS["clickhouse"],

(Can't make that an applyable suggestion since config.py isn't in the diff, sorry.)


superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py:195

When protocol=https becomes secure=true and the URI carries no explicit port, the effective port looks like it changes. On the target side I executed this against the pinned 1.7.2 rather than inferring it: default_port("http", secure=True) == 8443 and default_port("http", secure=False) == 8123, so the new driver resolves a port-less secure=true row to 8443.

The legacy half I could not run — clickhouse-sqlalchemy isn't installed in my environment — so "the old HTTP dialect defaults to 8123 regardless of protocol" comes from reading its source, not from executing it. You'll know better than me whether that holds. If it does, clickhouse://host/db?protocol=https moves from 8123 to 8443, and the string really is preserved byte-for-byte while the meaning shifts underneath it.

Could we pin :8123 explicitly when the rewrite introduces secure=true and no port is present — the same technique already used for native rows at :169-174?


…f7b3a9c14e02….py:222-228 and tests/unit_tests/migrations/test_migrate_clickhouse_to_clickhousedb.py:176-178

_remap_native_port decides the port at :222-226, but _migrate_query doesn't run until :228, so the port decision can't see the TLS flag. A native row carrying secure=true — preserved untouched per the docstring at :53-54 — ends up asserting TLS against 8123, the plaintext HTTP interface. The engine spec derives this correctly elsewhere via default_port("http", encryption) (superset/db_engine_specs/clickhouse.py:620).

The parametrised case at test :176-178 asserts exactly this output as correct, so the suite currently ratifies it rather than catching it — worth changing in the same pass.

WDYT about deriving the port from the post-_migrate_query secure value, or skipping native+TLS rows the way non-default-port rows already are?


…f7b3a9c14e02….py:200

Every parameter except protocol is carried across verbatim, but the two drivers don't share a vocabulary. The one that looks most likely to bite: the legacy HTTP dialect turns ?endpoint=clickhouse into the HTTP request path, whereas clickhouse-connect builds that from proxy_path and routes unrecognised kwargs into settings, where invalid_setting_action defaults to error. A connection behind a path-prefixed reverse proxy would migrate "successfully" and then stop addressing its route. Same shape for engine_reflection, alt_hosts, and ca_certs (spelled ca_cert in the target).

Could we translate the known-divergent names, or treat an unrecognised parameter as a skip-with-warning rather than a silent carry-over?


One thing that ties these together rather than being separate: with downgrade() a no-op at :260-265, none of the above is recoverable. The reasoning for the no-op is sound as far as it goes — a migrated row is textually indistinguishable from a natively-created one — but that's a consequence of not recording what was rewritten. Stashing (id, original_uri) and restoring only rows still matching the migration's own output would make it exactly reversible. The Databend precedent in-tree does this (2026-08-06_00-00_c4a1b8e2d739_databend_secure_to_sslmode.py:162-163). Worth noting the checklist ticks "supports rollback" against a pass body.

And a genuine question rather than a finding: should this be a migration at all? A schema migration that's wrong gets caught by CI, but this one is only wrong against a particular operator's ClickHouse topology, which CI can't see — whether HTTP is enabled, whether egress allows 8123. A superset CLI command with --dry-run, referenced from UPDATING.md, would keep the destructive step where the topology knowledge is. Entirely your call, and I may be over-weighting the risk.

Worth crediting: mirroring the Databend migration's shape — local shadow model, paginated_update, in-place query editing instead of round-tripping through URL.render_as_string — is the right instinct, and avoids silently reordering unrelated parameters. Skipping rather than guessing on non-default native ports and IPv6 hosts is the same instinct; the finding above is really that the skip list needs to reach the operator.

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #9aaf09

Actionable Suggestions - 1
  • superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py - 1
Additional Suggestions - 2
  • superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py - 2
    • URI parsing regression · Line 55-59
      The docstring claims credentials are preserved, but the refactored `_split_uri` scans the whole remainder for the first '/' or '?' from index 0. A password containing a raw '/' or '?' (e.g. `clickhouse://user:pa/ss@host:8123/db`) truncates the authority before the '@', so `hostport` becomes `user:pa` and the migrated URI is corrupted. The previous `_swap_native_default_port` searched from after the last '@' and handled this; restore that scan.
    • Logger name inconsistency · Line 100-100
      Other migrations in this repo consistently use `logging.getLogger("alembic.env")` (e.g. `ce6bd21901ab`, `2bee73611e32`). Using `"alembic"` here routes the overflow warning to a different logger that alembic's logging config may not capture, so the skip warning at line 235 could be silently dropped. Align with the `alembic.env` convention.
Review Details
  • Files reviewed - 2 · Commit Range: d8899a6..aa58f1e
    • superset/migrations/versions/2026-09-15_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py
    • tests/unit_tests/migrations/test_migrate_clickhouse_to_clickhousedb.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +191 to +201
rewritten = []
for pair in query.split("&"):
key, _, value = pair.partition("=")
if key == "protocol":
if value.lower() == "https":
rewritten.append("secure=true")
# protocol=http (the plaintext default) carries no meaning for
# clickhouse-connect and is dropped.
continue
rewritten.append(pair)
return "&".join(rewritten)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CWE-319: TLS Downgrade

When a legacy URI carries both protocol=https and an existing secure param, _migrate_query appends secure=true without removing the old one, producing e.g. secure=true&secure=false. get_parameters_from_uri does dict(url.query) (last-wins), so encryption resolves to False — a silent TLS downgrade to plaintext, exactly what this migration exists to prevent. Drop any pre-existing secure when protocol=https. (CWE-319)

Code suggestion
Check the AI-generated fix before applying
Suggested change
rewritten = []
for pair in query.split("&"):
key, _, value = pair.partition("=")
if key == "protocol":
if value.lower() == "https":
rewritten.append("secure=true")
# protocol=http (the plaintext default) carries no meaning for
# clickhouse-connect and is dropped.
continue
rewritten.append(pair)
return "&".join(rewritten)
rewritten = []
force_secure = any(
key == "protocol" and value.lower() == "https"
for key, _, value in (pair.partition("=") for pair in query.split("&"))
)
for pair in query.split("&"):
key, _, value = pair.partition("=")
if key == "protocol":
if force_secure:
rewritten.append("secure=true")
# protocol=http (the plaintext default) carries no meaning for
# clickhouse-connect and is dropped.
continue
if force_secure and key == "secure":
# protocol=https forces TLS; drop any pre-existing secure flag so
# the query never carries conflicting/duplicate secure values.
continue
rewritten.append(pair)
return "&".join(rewritten)

Code Review Run #9aaf09


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@github-actions

Copy link
Copy Markdown
Contributor

🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️❗ @eschutho Your base branch master has also updated superset/migrations.

Please consider rebasing your branch and resolving potential db migration conflicts.

3 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️❗ @eschutho Your base branch master has also updated superset/migrations.

Please consider rebasing your branch and resolving potential db migration conflicts.

@github-actions

Copy link
Copy Markdown
Contributor

🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️❗ @eschutho Your base branch master has also updated superset/migrations.

Please consider rebasing your branch and resolving potential db migration conflicts.

@github-actions

Copy link
Copy Markdown
Contributor

🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️ 🙅‍♂️❗ @eschutho Your base branch master has also updated superset/migrations.

Please consider rebasing your branch and resolving potential db migration conflicts.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

4 similar comments
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@eschutho
eschutho force-pushed the sc-120997-clickhouse-legacy-migration branch from 0f0043b to 0eae123 Compare November 4, 2026 01:34
for row in rows:
last_id = row.id
try:
migrated = _rewrite(row.sqlalchemy_uri)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks sqlalchemy_uri, but extra.engine_params.connect_args is forwarded to the new driver untouched. A legacy row with connect_args={"timeout": 30} now sends that to clickhouse-connect as a ClickHouse server setting, so every query fails with an unknown-setting error, and a CA path in verify is coerced to False by clickhouse-connect, which silently turns certificate verification off. Should rows with non-empty connect_args be skipped and logged like the other unmapped parameters?

databases.c.id == row.id,
databases.c.sqlalchemy_uri == row.sqlalchemy_uri,
)
.values(sqlalchemy_uri=migrated)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rewrites sqlalchemy_uri but leaves configuration_method as it was (sqlalchemy_form for rows saved through the legacy spec), and the edit modal picks its form from that field (DatabaseModal/index.tsx:783) while the dynamic-form switch is hidden in edit mode (:2242). Migrated connections would still open on the SQLAlchemy URI editor instead of the new form. Should the migration also set configuration_method to dynamic_form for rewritten rows, and restore it on downgrade?

Comment thread UPDATING.md Outdated
URI parameters, a non-default native port, native TLS) stay on the legacy driver
and are logged by database id during the upgrade for manual migration. A
downgrade restores the original URI of every converted connection that has not
been edited since. `DISALLOWED_SQL_FUNCTIONS` gains a `clickhousedb` entry

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIME_GRAIN_ADDON_EXPRESSIONS is looked up by the spec's engine, so a custom grain configured under clickhouse (the 2-second example in config.py) stops resolving once the row is clickhousedb, and saved charts using it raise No grain spec for PT2S for database clickhousedb. The note only covers DISALLOWED_SQL_FUNCTIONS; should it also tell operators to copy their clickhouse time-grain entries to clickhousedb?

Comment thread superset/config.py
# The lookup is keyed by engine spec ``engine``: ClickHouse connections use
# ``clickhouse`` (clickhouse-sqlalchemy) or ``clickhousedb`` (clickhouse-connect),
# and both drivers reach the same server functions.
DISALLOWED_SQL_FUNCTIONS["clickhousedb"] = set(DISALLOWED_SQL_FUNCTIONS["clickhouse"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the only thing keeping rewritten connections under the ClickHouse function denylist, but nothing fails if it is dropped: the existing denylist tests either patch the config or use PostgreSQL. Could a test run an enforcement path with ClickHouseConnectEngineSpec and the default config and assert that SELECT version() is rejected while SELECT 1 passes?

eschutho and others added 4 commits November 6, 2026 00:36
…-connect

Rewrites the sqlalchemy_uri of Database rows on the legacy `clickhouse`
backend (clickhouse-sqlalchemy driver) to `clickhousedb+connect://` so they
resolve to ClickHouseConnectEngineSpec and render the new dynamic connection
form.

- HTTP schemes (clickhouse://, clickhouse+http://) change scheme only; the
  HTTP port (8123) is preserved byte-for-byte along with credentials, database
  and query string.
- Native schemes (clickhouse+native://, clickhouse+asynch://) also move the
  native default port 9000 to the HTTP port 8123 because clickhouse-connect is
  HTTP-only. Non-default native ports are left on the legacy driver.
- Idempotent (rows already on clickhousedb are skipped). Downgrade is a
  documented no-op: migrated rows are indistinguishable from natively-created
  clickhousedb connections and remain functional after a rollback.
- Merges the two open revision heads (88a01c781622, c7f53d184ea2).

Story: https://app.shortcut.com/preset/story/120997

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Addresses PR review feedback:
- Map legacy `protocol=https` to clickhouse-connect's `secure=true` (and drop
  the meaningless `protocol` param) so migrated TLS connections are not
  silently downgraded to plaintext HTTP (CWE-319).
- Bound the credential-separator `@` search to the authority so an `@` in the
  path or query no longer corrupts host detection.
- Skip (with a warning) rows whose rewritten URI would exceed the
  dbs.sqlalchemy_uri 1024-char column limit rather than truncating them.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Reparent onto master's single head b8f3a2c91d64. #44288 merged the two
  former parents into e2f3a1b9c640, and several merges have since stacked
  on top of it, so the old tuple re-forked the graph.
- HTTP rows: the legacy driver ignores `secure` and defaults to 8123 even
  for `protocol=https`, so drop stray `secure` (no duplicates / no silent
  plaintext->TLS flip) and pin 8123 when `secure=true` is introduced
  without a port (clickhouse-connect would otherwise pick 8443).
- Native rows carrying TLS (`secure=true`) are skipped instead of being
  pointed at the plaintext HTTP port.
- Parameters the drivers don't share (endpoint, timeout, ca_certs,
  header__*, a CA-path `verify`, ...) are no longer carried verbatim; the
  row stays on the legacy driver and its id is logged for the operator.
- Exact rollback: upgrade records the original URI and a fingerprint of
  the migrated state in a migration-owned table; downgrade restores only
  unchanged converted rows, then drops the table (Databricks precedent).
- Add `clickhousedb` to DISALLOWED_SQL_FUNCTIONS so the ClickHouse
  denylist follows rewritten rows.
- Document the change in UPDATING.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, denylist)

- Skip (and log by id) rows whose extra.engine_params.connect_args is
  non-empty, or whose extra cannot be inspected. clickhouse-connect sends
  unknown keys such as `timeout` to the server as settings (every query
  fails) and coerces a CA-bundle path in `verify` to False, silently
  disabling certificate verification.
- Set configuration_method to `dynamic_form` on converted rows so the edit
  modal opens the new form; record the original value and restore it on
  downgrade alongside the URI (it is part of the rollback fingerprint).
- Add `time_grain_addon_aliases` to engine specs; ClickHouseConnectEngineSpec
  declares ("clickhouse",), so TIME_GRAIN_ADDON_EXPRESSIONS configured under
  `clickhouse` keep resolving for converted connections (both in
  get_time_grain_expressions and the partition-mirroring width check), with
  `clickhousedb` entries taking precedence.
- Test that the default config's ClickHouse function denylist is enforced
  on a clickhousedb connection: `SELECT version()` is rejected and
  `SELECT 1` runs, without patching config.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eschutho
eschutho force-pushed the sc-120997-clickhouse-legacy-migration branch from 0eae123 to eba10e7 Compare November 6, 2026 00:56
A stale local ruff reformatted two existing asserts; restore master's
formatting so the file only carries the new test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eschutho

eschutho commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

@sadpandajoe thanks for the review. All four points are addressed in eba10e7bfb and 0127f202f5.

1. extra.engine_params.connect_args forwarded untouched (thread)
A legacy row is no longer converted when its connect_args is non-empty, or when extra can't be inspected (invalid JSON, or not an object). It stays on the legacy driver, which keeps working, and superset db upgrade logs its database id along with the offending keys, e.g. Leaving ClickHouse database id=903 on the legacy clickhouse driver (extra.engine_params.connect_args would be passed to clickhouse-connect unchanged ('timeout')). That covers both failure modes you described: a stray timeout sent to the server as a setting, and a CA path in verify silently coerced to False. Nothing under connect_args is translated or carried across. Tests cover timeout, a CA-path verify, and malformed extra, as well as extra without connect_args (still converted).

2. configuration_method left as sqlalchemy_form (thread)
Converted rows get configuration_method = 'dynamic_form', so the edit modal opens the new form. The original value is stored in the migration's bookkeeping table and is part of the rollback fingerprint, and downgrade restores it together with the original URI. Skipped rows keep sqlalchemy_form, which matches the editor they can still be edited in.

3. TIME_GRAIN_ADDON_EXPRESSIONS keyed by clickhouse (thread)
This is a code fix, not just a docs note, since a migration can't rewrite an operator's superset_config.py. Engine specs gain time_grain_addon_aliases, and ClickHouseConnectEngineSpec declares ("clickhouse",). Custom grains configured under clickhouse (the PT2S example) therefore keep resolving for converted connections, so saved charts don't hit No grain spec for PT2S. Entries under clickhousedb take precedence. The alias applies in get_time_grain_expressions and in the partition-mirroring grain_bucket_width check, so an operator-redefined built-in grain still skips mirroring on clickhousedb. UPDATING.md documents this. It also says deployments that override DISALLOWED_SQL_FUNCTIONS must add a clickhousedb entry, because that lookup has no alias.

4. Denylist enforcement untested on clickhousedb (thread)
test_execute_default_denylist_applies_to_clickhouse_connect runs Database.execute on a clickhousedb+connect:// connection against the unpatched default config. It asserts that SELECT version() is rejected as a disallowed function and that SELECT 1 runs. I checked that it fails when the DISALLOWED_SQL_FUNCTIONS["clickhousedb"] line is removed.

Verification

  • 49 migration tests run against real Alembic operations.
  • A real flask db upgrade → downgrade → upgrade cycle on SQLite restored the original URIs and configuration_method byte-for-byte. It left a connect_args row on the legacy driver and didn't touch a connection created directly on clickhousedb.
  • Rebased on current master (c01ffe6eb7); superset db heads still reports a single head.
  • CI on 0127f202f5 is green: all checks pass, including unit-tests, test-postgres, test-mysql, enforce-single-migration-head, and docker-build (dev).

cc @rusackas: the branch is rebased onto current master, and the migration parents on master's actual single head, b8f3a2c91d64. That isn't e2f3a1b9c640 from the suggestion: several merges have stacked on top of e2f3a1b9c640 since, so parenting on it would re-fork the graph. Ready for another look whenever you have time.

@eschutho

eschutho commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

@sadpandajoe quick heads up — all four points from your review are addressed (details and tests in this reply, commits eba10e7b/0127f202f5), and CI is green on the current head. Would appreciate another look when you have a chance.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@eschutho
eschutho requested a review from sadpandajoe November 19, 2026 22:58
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eschutho, really thorough work here, and nice to see the UPDATING.md note already covering the driver swap.

One thing before approving... #43499 landed on master today with dfa683969f48, which also chains off b8f3a2c91d64, so after the merge from master this leaves two heads. That's what enforce-single-migration-head and the test jobs are tripping on. Can you repoint down_revision (and the Revises: line in the docstring) at dfa683969f48?

Heads up that #44278 hangs off b8f3a2c91d64 too, so whichever of the two lands second will need the same repoint.


# revision identifiers, used by Alembic.
revision = "f7b3a9c14e02"
down_revision = "b8f3a2c91d64"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do it, plus the matching Revises: line up top:

Suggested change
down_revision = "b8f3a2c91d64"
down_revision = "dfa683969f48"

Comment thread UPDATING.md
Comment on lines +235 to +236
`superset db upgrade`, so they use the dynamic connection form. Install
`clickhouse-connect>=0.13.0` before upgrading. HTTP connections keep their port;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one, 0.13.0 is well below what the clickhouse extra in pyproject.toml pins on master (>=1.11.0, <2.0), so pointing folks at the extra seems safer:

Suggested change
`superset db upgrade`, so they use the dynamic connection form. Install
`clickhouse-connect>=0.13.0` before upgrading. HTTP connections keep their port;
`superset db upgrade`, so they use the dynamic connection form. Install the
`clickhouse` extra (`clickhouse-connect>=1.11.0, <2.0`) before upgrading. HTTP connections keep their port;

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review: the earlier migration-head conflict and the concrete denylist, TLS/port, rollback, parameter-handling, and edit-form issues are addressed in this head. The required checks are green. Thanks for working through this substantial migration.

@rusackas, the migration now chains off dfa683969f48, so the head conflict you mentioned is fixed. The PR summary still says b8f3a2c91d64 and could be updated to match.

  • superset/migrations/versions/2026-11-23_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py:385-394: downgrade() checks a fingerprint containing the URI, form, and changed_on, but its update then matches only id and URI. An edit to the form or extra between the read and update can be followed by restoration against that newer state. Could the update also match the checked configuration_method and changed_on, and warn when no row is updated? The upgrade already uses a conditional update for its URI.
  • UPDATING.md:247: Evan's existing suggestion is still applicable: the install note says clickhouse-connect>=0.13.0, while the clickhouse extra in pyproject.toml requires >=1.11.0, <2.0.

I did not rerun a live ClickHouse connection; this review covers the exact current PR diff and its green CI evidence.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eschutho, the repoint is in. But #46479 landed on master right after with a7d29bc4e681, which also hangs off dfa683969f48... so we're back to two heads. Mind moving down_revision (and the Revises: line) to a7d29bc4e681?

Also, my UPDATING.md suggestion on the clickhouse-connect version is still open.


# revision identifiers, used by Alembic.
revision = "f7b3a9c14e02"
down_revision = "dfa683969f48"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal as last time, plus the Revises: line up top:

Suggested change
down_revision = "dfa683969f48"
down_revision = "a7d29bc4e681"

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at e906ddf1: comment, no blocker. The only PR change since my last review is the re-point to a7d29bc4e681. The nine-file diff is otherwise identical after the master merge, but master has moved again.

Earlier points

  • down_revision head conflict: fixed for a7d29bc4e681, but see the first item below.
  • downgrade() conditional update (superset/migrations/versions/2026-11-23_00-00_f7b3a9c14e02_migrate_clickhouse_to_clickhousedb.py:385-394): still open. The UPDATE matches only id and URI, not the checked configuration_method/changed_on, and the rowcount isn't checked.
  • UPDATING.md:280: still says clickhouse-connect>=0.13.0, while the clickhouse extra pins >=1.11.0, <2.0 (Evan's suggestion still applies).

New

  • …f7b3a9c14e02….py:98,119: master now has 7b9d2f8a6c31 (add_teams_installations, #45508), which also revises a7d29bc4e681, so merging as-is creates two heads. It needs one more re-point to 7b9d2f8a6c31 right before merge.
  • …f7b3a9c14e02….py:242: a plaintext legacy row on port 8443 or 443 would switch to TLS. The rewrite drops protocol=http/secure and emits nothing for plaintext. clickhouse-connect's create_client sets use_tls when no interface is given and the port is 443/8443, and the SQLAlchemy dialect passes no interface. So clickhouse://host:8443/db (plaintext under the legacy driver) becomes a TLS connection. That's an unusual setup, but it breaks the "meaning carried across exactly" rule in the docstring. Emitting secure=false for non-TLS rows on those ports, or skipping them, would close it. A test case next to the :8443 one at tests/unit_tests/migrations/test_migrate_clickhouse_to_clickhousedb.py:128 would cover it.
  • …f7b3a9c14e02….py:286 (minor): when connect_args isn't a dict, the exception embeds connect_args!r, and :329-333 logs it at WARNING. A malformed string or list carrying a credential would end up in deploy logs. A fixed reason for the non-dict case avoids that.

CI: the red validate-all-ghas is the zizmor SARIF upload step. This PR touches no workflows, so it doesn't look related.

I didn't run a live ClickHouse connection. The TLS point comes from reading the clickhouse-connect driver source, not from a connection test.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@eschutho the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preset-io risk:db-migration PRs that require a DB migration size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants