agronholm / agronholm/sqlacodegen

Clickhouse generation creating invalid python

Abierto
#469 19 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
2.4k
Forks
284
Merge medio
2 d 1 h
PR fusionados (30 d)
1

Descripción

### Things to check first

- [x] I have searched the existing issues and didn't find my bug already reported there

- [x] I have checked that my bug is still present in the latest release

### Sqlacodegen version

4.0.2

### SQLAlchemy version

2.0.48

### RDBMS vendor

Other

### What happened?

Invalid python is generated when parsing the given clickhouse DB schema

```python
from typing import Any

from clickhouse_sqlalchemy.types.common import Array, UUID
from sqlalchemy import text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.sql.sqltypes import NullType

class Base(DeclarativeBase):
pass

class Testtable(Base):
__tablename__ = 'testtable'

id: Mapped[str] = mapped_column(UUID, primary_key=True) # This should be uuid.UUID
col1: Mapped[list] = mapped_column(Array(), nullable=False)
col2: Mapped[list] = mapped_column(Array(), nullable=False, server_default=text('[]'))
col3: Mapped[Any] = mapped_column(NullType, nullable=False) # NOTE - This is also weird as it should be JSON
col4: Mapped[list] = mapped_column(Array(), nullable=False)
col5: Mapped[list] = mapped_column(Array(), nullable=False)
col6: Mapped[list] = mapped_column(Array(), nullable=False)
```

There are also warnings regarding the JSON type:
```
/Users/user/.cache/uv/archive-v0/aS1Ku1BPpSOILuRQTOKY0/lib/python3.14/site-packages/clickhouse_sqlalchemy/drivers/base.py:309: SAWarning: Did not recognize type 'JSON' of column 'col3'
warn("Did not recognize type '%s' of column '%s'" %
/Users/user/.cache/uv/archive-v0/aS1Ku1BPpSOILuRQTOKY0/lib/python3.14/site-packages/clickhouse_sqlalchemy/drivers/base.py:309: SAWarning: Did not recognize type 'JSON' of column 'col4'
warn("Did not recognize type '%s' of column '%s'" %
```

### Database schema for reproducing the bug

```sql
DROP TABLE IF EXISTS testtable;
CREATE TABLE IF NOT EXISTS testtable
(
id UUID,
col1 Array(String),
col2 Array(String) DEFAULT [],
col3 JSON,
col4 Array(JSON),
col5 Array(UUID),
col6 Array(Int32)

) ENGINE = MergeTree()
ORDER BY (id);
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.