Skip to content

Exception when using send_logs_level=test setting #383

@the-horhe

Description

@the-horhe

Describe the bug
Client raises exception when receive send_logs_level=test is set. It works fine with other levels though.

To Reproduce

from clickhouse_driver.client import Client
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

client = Client(host="localhost", settings={
    "send_logs_level": "test",
})
client.execute("CREATE DATABASE IF NOT EXISTS test")
client.execute("CREATE TABLE IF NOT EXISTS test.some_log (id UInt32, msg String) ENGINE MergeTree ORDER BY id")

client.execute("INSERT INTO test.some_log VALUES", [(1, "s1"), (2, "s2")])

This leads to en error:

Traceback (most recent call last):
  File "/src/log_bug.py", line 15, in <module>
    client.execute("INSERT INTO test.some_log VALUES", [(1, "s1"), (2, "s2")])
  File "/usr/local/lib/python3.11/dist-packages/clickhouse_driver/client.py", line 351, in execute
    rv = self.process_insert_query(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/clickhouse_driver/client.py", line 580, in process_insert_query
    self.receive_end_of_query()
  File "/usr/local/lib/python3.11/dist-packages/clickhouse_driver/client.py", line 640, in receive_end_of_query
    packet = self.connection.receive_packet()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/clickhouse_driver/connection.py", line 521, in receive_packet
    log_block(packet.block)
  File "/usr/local/lib/python3.11/dist-packages/clickhouse_driver/log.py", line 31, in log_block
    priority = row[0]
               ~~~^^^
KeyError: 0

Just before an error row variable contains the following:

{'event_time': datetime.datetime(2023, 7, 5, 12, 51, 41), 'event_time_microseconds': 915779, 'host_name': 'clickhouse', 'query_id': '431ae6be-f93b-493b-81e9-591c8bda6fc6', 'thread_id': 622, 'priority': 9, 'source': 'test.some_log (b9f367a7-6993-49f7-8185-e6c46f8d575f)', 'text': 'preparePartForCommit: inserting all_5_5_0 (state PreActive) into data_parts_indexes'}

Looks like the problem is here. Client tries to get priority level by code (9 in this case), fails and uses some fallback behavior priority = row[0]

Expected behavior
Logs with level test are shown among other logs.

Versions

  • Version of package with the problem: 0.2.6
  • ClickHouse server version: 23.5.1.1
  • Python version: 3.11.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions