Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table reflection for DateTime64 timezone will be extra quoted #310

Open
littlebtc opened this issue May 9, 2024 · 0 comments
Open

Table reflection for DateTime64 timezone will be extra quoted #310

littlebtc opened this issue May 9, 2024 · 0 comments

Comments

@littlebtc
Copy link
Contributor

Describe the bug
Table reflection for DateTime64 timezone will be extra quoted

To Reproduce
If you have a table like

class TestTable(Base):
    time = Column(types.DateTime64(3, "UTC"), primary_key=True)
    __tablename__ = "test_table"
    __table_args__ = (engines.MergeTree(order_by=("time",)),)

The first migration and table creation will work as expected.
But running alembic revision --autogenerate after table created, something weird will happen:

INFO  [alembic.autogenerate.compare] Detected type change from DateTime64(timezone="'UTC'") to DateTime64(timezone='UTC') on 'test_table.time'

After tracing the code, it seems that _parse_detetime64_params did not handle the quotes correctly; when the inner spec is 3, 'UTC', it will return [3, "'UTC'"] thus hit the issue. In my own code I create patch to clickhouse_sqlalchemy.drivers.base.ClickHouseDialect._parse_detetime64_params:

    # ...
    if len(params) > 1:
        params[1] = params[1].strip()[1:-1]
    # ...

It looks dirty but the autogenerate works correctly.

Expected behavior

_parse_detetime64_params shall return [3, "UTC"] for inner spec like 3, 'UTC', not resulting weird detected type change.

Versions

  • clickhouse-sqlalchemy 0.3.1
  • SQLAlchemy 2.0.29
  • Python 3.11
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

No branches or pull requests

1 participant