mymarilyn / clickhouse-driver

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

Access the database after disconnecting #398

Open vivinamalraj opened 1 year ago

vivinamalraj commented 1 year ago

Access the database after disconnecting I can able to execute queries on a ClickHouse database after disconnecting the client without encountering a NetworkError as expected.

To Reproduce

Modules

from clickhouse_driver import Client from clickhouse_driver.errors import NetworkError

Create a ClickHouse client

client = Client( host=host, port=9000, database='ClickHouse_DB' user='default', password='pass', )

try:

Execute the first query

response = client.execute("describe table_name")
print(response)

except NetworkError as e: print(f"Error: {e}") print("The client encountered a NetworkError.")

Disconnect the ClickHouse client

client.disconnect()

try:

Attempt to execute a query after disconnecting (this will likely raise a NetworkError)

response = client.execute("describe table_name")
print(response)

except NetworkError as e: print(f"Error: {e}") print("The client encountered a NetworkError after disconnecting.")

Expected behavior NetworkError excepted.

Versions

bsushmith commented 5 days ago

This doesn't seem like an issue. The execute method makes a new connection if no connection is available. https://github.com/mymarilyn/clickhouse-driver/blob/0.2.6/clickhouse_driver/client.py#L315-L324