ClickHouse / ClickHouse/clickhouse-connect

[sqlalchemy]: LowCardinality and Nullable are annotated as returning ChSqlaType

Open Beginner friendly
#1,033 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
521
Forks
159
Avg merge
1d 8h
Merged PRs (30d)
43

Description

### Describe the bug
`clickhouse_connect.cc_sqlalchemy.datatypes.sqltypes.LowCardinality` is a function annotated as retuning
`ChSqlaType`, which is a mixin that does not extend `sqlalchemy.types.TypeEngine`. The problem of this is that mypy (strict) flags columns declared as `Column("hostname", LowCardinality(String))`:

```
error: Argument 2 to "Column" has incompatible type "ChSqlaType"; expected
"type[TypeEngine[Any]] | TypeEngine[Any] | SchemaEventTarget | None" [arg-type]
```

At runtime the returned object is an instance of the wrapped class (`String`), which is a `TypeEngine`.

The same applies to `Nullable()`.

### Expected behaviour
The annotation reflects the runtime type, e.g. a `TypeVar` bound to `ChSqlaType & TypeEngine` so
`LowCardinality(String)` is typed as `String`, or at least `-> TypeEngine[Any]`.

### Code example

```python
from sqlalchemy import Column
from clickhouse_connect.cc_sqlalchemy.datatypes.sqltypes import LowCardinality, String

Column("hostname", LowCardinality(String)) # mypy --strict: arg-type
```

### Configuration
#### Environment
* clickhouse-connect version: `main` at 87ccee0a
* SQLAlchemy version: 2.0.52
* mypy 2.3.1 / zuban 0.9.1, Python 3.14

Contributor guide

Open the contributing guide

Research direction

Start in `clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py` and inspect the annotations for `LowCardinality` and `Nullable`, comparing them with the runtime types described in the issue. Use the shown `Column("hostname", LowCardinality(String))` example with mypy strict; done means the annotation reflects a type accepted by SQLAlchemy without the reported arg-type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.