agronholm / agronholm/sqlacodegen

Clickhouse generation creating invalid python

オープン
#469 コメント 19 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
2.4k
フォーク
284
平均マージ
2日 1時間
マージ済み PR(30日)
1

説明

### 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);
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。