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

Enum + Clickhouse 1.4 = crash #192

Closed
anatoly-scherbakov opened this issue Aug 16, 2022 · 0 comments · Fixed by #263
Closed

Enum + Clickhouse 1.4 = crash #192

anatoly-scherbakov opened this issue Aug 16, 2022 · 0 comments · Fixed by #263

Comments

@anatoly-scherbakov
Copy link

anatoly-scherbakov commented Aug 16, 2022

Describe the bug

In certain circumstances, when querying a table with an Enum column an error is thrown:

File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 393, in _raw_all_rows
return [make_row(row) for row in rows]
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 393, in
return [make_row(row) for row in rows]
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/sqltypes.py", line 1768, in process
value = parent_processor(value)
TypeError: expected bytes, str found

To Reproduce

  • Create a table with a clickhouse_sqlalchemy.types.Enum field
  • Fill it with data
  • SELECT some data from it via SQLAlchemy

Expected behavior

The same code worked correctly on SQLAlchemy 1.3 and it was expected for it to continue that way.

How to fix

Method 1:

    engine = create_engine(...)
    engine.dialect.returns_unicode_strings = String.RETURNS_UNICODE

After this change, String.result_processor method will invoke processors.to_conditional_unicode_processor_factory() instead of processors.to_unicode_processor_factory() to obtain the result converting function.

Method 2: in addition to the above, assign:

    engine.dialect.convert_unicode = False

This will mean that no conversion at all will happen because SQLAlchemy will expect to receive proper Unicode strings from the driver. This should provide a bit higher performance.

Versions

Python: 3.8.12.
Libraries:

SQLAlchemy = "^1.4"
clickhouse-sqlalchemy = "^0.2.1"
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

Successfully merging a pull request may close this issue.

1 participant