Skip to content

fix: don't set nullable modifier when nullable is embedded in LowCardinality type string#141

Merged
rmorehig merged 1 commit intomainfrom
fix/low-cardinality-nullable-double-wrap
Mar 25, 2026
Merged

fix: don't set nullable modifier when nullable is embedded in LowCardinality type string#141
rmorehig merged 1 commit intomainfrom
fix/low-cardinality-nullable-double-wrap

Conversation

@gnzjgo
Copy link
Copy Markdown
Member

@gnzjgo gnzjgo commented Mar 25, 2026

Problem

When chaining t.string().lowCardinality().nullable(), the SDK correctly produces the ClickHouse type string LowCardinality(Nullable(String)), but also sets nullable: true in the column modifiers metadata.

The backend (datasource_schema.py) checks whether to wrap the type with Nullable() by testing if the type string starts with "Nullable(". Since LowCardinality(Nullable(String)) starts with "LowCardinality(", the check passes and the backend wraps it again, producing Nullable(LowCardinality(Nullable(String))) — which ClickHouse rejects.

Fix

Omit the nullable modifier flag from column metadata when nullable is already encoded inside the LowCardinality(...) type string wrapper. This applies to both chaining orders:

  • .lowCardinality().nullable()
  • .nullable().lowCardinality()

The type string itself remains correct (LowCardinality(Nullable(X))), and the backend no longer redundantly wraps it.

…inality type string

When chaining .lowCardinality().nullable() or .nullable().lowCardinality(),
the SDK correctly produces the type string LowCardinality(Nullable(X)).
However, it also set nullable: true in the column modifiers metadata.

The backend checks modifiers.nullable and wraps the type with Nullable()
if the type string doesn't start with 'Nullable('. Since
LowCardinality(Nullable(X)) starts with 'LowCardinality(', the backend
would double-wrap it into Nullable(LowCardinality(Nullable(X))), which
ClickHouse rejects.

Fix: omit the nullable modifier flag when nullable is already encoded
inside the LowCardinality type string wrapper.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d247b-1dfc-764a-ae09-697511e5209f
@gnzjgo gnzjgo force-pushed the fix/low-cardinality-nullable-double-wrap branch from 0f860b5 to 6c35e51 Compare March 25, 2026 10:30
@gnzjgo
Copy link
Copy Markdown
Member Author

gnzjgo commented Mar 25, 2026

tested that deployment works
CleanShot 2026-03-25 at 11 31 14@2x

@gnzjgo gnzjgo requested review from juliavallina and rmorehig March 25, 2026 10:32
@rmorehig rmorehig merged commit a94fed9 into main Mar 25, 2026
2 checks passed
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.

2 participants