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

Httpclient error when executing INSERT INTO with LIMIT 0 #389

Closed
treysp opened this issue Aug 22, 2024 · 0 comments · Fixed by #400
Closed

Httpclient error when executing INSERT INTO with LIMIT 0 #389

treysp opened this issue Aug 22, 2024 · 0 comments · Fixed by #400
Labels
bug Something isn't working

Comments

@treysp
Copy link

treysp commented Aug 22, 2024

Describe the bug

When I execute an INSERT INTO command using the httpclient, it returns an error if the insert query contains LIMIT 0.

Steps to reproduce

  1. Create a table in Clickhouse or Clickhouse cloud
  2. Use the httpclient to execute an INSERT INTO command whose query contains LIMIT 0

Expected behaviour

No error. (I realize that inserting the results of a query that returns no rows is pointless, but here we are.)

Code example

> self.execute("CREATE OR REPLACE TABLE test_insert (col1 Int8) order by ();")
> self.execute("INSERT INTO test_insert SELECT 1 LIMIT 0;")

Traceback (most recent call last):
  File ".venv/lib/python3.11/site-packages/clickhouse_connect/dbapi/cursor.py", line 56, in execute
    query_result = self.client.query(operation, parameters)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/clickhouse_connect/driver/client.py", line 209, in query
    return self._query_with_context(query_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/clickhouse_connect/driver/httpclient.py", line 210, in _query_with_context
    for col in json_result['meta']:
               ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'json_result' where it is not associated with a value

Executing the same INSERT INTO query without LIMIT 0 works as expected and nothing is printed to terminal:

> self.execute("INSERT INTO test_insert SELECT 1;")

Configuration

Environment

  • clickhouse-connect version: 0.7.18
  • Python version: 3.11.6
  • Operating system: MacOS Ventura 13.4.1

ClickHouse server

  • ClickHouse Server version: 24.7.3.42
@treysp treysp added the bug Something isn't working label Aug 22, 2024
@genzgd genzgd mentioned this issue Sep 26, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant