Skip to content

fix: spurious schema change for named Tuple columns on the HTTP driver - #836

Open
Ragdoll-dbs wants to merge 5 commits into
ClickHouse:mainfrom
Ragdoll-dbs:fix/http-named-tuple-schema-change
Open

Ragdoll-dbs wants to merge 5 commits into
ClickHouse:mainfrom
Ragdoll-dbs:fix/http-named-tuple-schema-change

Conversation

@Ragdoll-dbs

@Ragdoll-dbs Ragdoll-dbs commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Fixes #835

On the HTTP driver, incremental models with on_schema_change: fail or append_new_columns fail when they have a named Tuple column, even though the schema hasn't changed:

Source columns not in target: []
Target columns not in source: []
New column types: ['tags Array(Tuple(`id` UInt64, `name` String))']

check_incremental_schema_changes compares type names as plain strings, but the two sides come from different places:

  • The existing table's types come from system.columns, which uses the server's spelling: Array(Tuple(id UInt64, name String, request_count UInt64)).
  • The query's types come from clickhouse-connect, which rebuilds the name. It backquotes every tuple element name and writes JSON(max_dynamic_paths = 10) where the server writes max_dynamic_paths=10.

The bug already existed, but #802 made it much more common. Models without a unique_key used to skip the schema check, and they now run it.

The schema check now compares both types with comparable_type_name() (in column.py), which ignores quotes that aren't needed, whitespace around (, ), , and =, and escaping differences. String literals such as Enum values and time zones are left as they are.

The comparison is shared by incremental, distributed_incremental, table (mv_on_schema_change) and materialized_view, so the fix covers all four. On the native driver both sides already used the server's spelling, so nothing changes there.

Tests:

  • Unit tests (tests/unit/test_type_comparison.py):
    • Server spellings, run through clickhouse-connect's own parser, compare equal to what the HTTP driver reports. This covers element names the server quotes in some versions but not others, it's, and JSON parameters.
    • Types that really differ still compare different.
    • check_incremental_schema_changes ignores the HTTP spelling but still detects a real type change inside a tuple.
  • Integration test TestNamedTupleSchemaChange: it mirrors the model from on_schema_change fails with a spurious type change for named Tuple columns on the HTTP driver since 1.10.4 #835, with no unique_key, on_schema_change='fail' and an empty array of named tuples, plus a tuple whose elements are named from and table.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A changelog entry was added following Updating the Changelog (user-facing, concise, PR link)

Note

Medium Risk
Touches shared schema-change and contract validation paths; logic is comparison-only (DDL unchanged) but incorrect normalization could mask real type mismatches.

Overview
Fixes false schema-change and contract failures on the HTTP driver when column types are semantically the same but spelled differently (e.g. Tuple(id UInt64) vs Tuple(\id` UInt64), or JSON(max_dynamic_paths=10)vs spaced=`).

Adds comparable_type_name() in column.py to normalize identifier quoting and punctuation spacing for comparisons only, plus adapter.data_types_match() wired into check_incremental_schema_changes and clickhouse__get_assert_columns_equivalent so on_schema_change / mv_on_schema_change and enforced contracts compare normalized types instead of raw strings. Unit and integration tests cover named tuples, JSON, and real type changes inside tuples.

Reviewed by Cursor Bugbot for commit e9b7d66. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-assistant

cla-assistant Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Ragdoll-dbs
Ragdoll-dbs force-pushed the fix/http-named-tuple-schema-change branch from ec64995 to 58132aa Compare November 27, 2026 19:27

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread dbt/adapters/clickhouse/httpclient.py Resolved
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit dd45a0c. Configure here.

Comment thread dbt/adapters/clickhouse/impl.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

on_schema_change fails with a spurious type change for named Tuple columns on the HTTP driver since 1.10.4

1 participant