agronholm / agronholm/sqlacodegen

Clickhouse generation creating invalid python

Đang mở
#469 19 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
2.4k
Fork
284
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.