mymarilyn / clickhouse-driver

ClickHouse Python Driver with native interface support
https://clickhouse-driver.readthedocs.io
Other
1.21k stars 213 forks source link

Failed enum insert when types_check enabled #328

Open fonz-zz opened 2 years ago

fonz-zz commented 2 years ago

Describe the bug In the documentation it is written that supported types for enum inserts are: Enum, int, long, str/basestring. https://clickhouse-driver.readthedocs.io/en/latest/types.html#enum8-16 Executing the example from the documentation works fine, except when check_types is enabled, than it fails with the following msg:

python3.7/site-packages/clickhouse_driver/columns/intcolumn.py", line 31, in before_write_items
    if item >= 0:
TypeError: '>=' not supported between instances of 'str' and 'int'

To Reproduce

client.execute('DROP TABLE IF EXISTS test')

client.execute('''
    CREATE TABLE test
    (
        x Enum8('foo' = 1, 'bar' = 2)
    ) ENGINE = Memory
''')

client.execute(
    'INSERT INTO test (x) VALUES',
    [{'x': MyEnum.foo}, {'x': 'bar'}, {'x': 1}],
    types_check=True
)

print(
    client.execute('SELECT * FROM test')
)

Expected behavior insert without error

Versions

AlexFrundin commented 11 months ago

I came across the same bug((

selevit commented 2 months ago

Same