Skip to content

Fix empty insert caused RuntimeError #361

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

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Client/ClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ void ClientBase::processInsertQuery(String query, ASTPtr parsed_query)

/// Process the query that requires transferring data blocks to the server.
const auto & parsed_insert_query = parsed_query->as<ASTInsertQuery &>();
if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(*std_in))))
if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (true /* is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(*std_in)) */))
{
const auto & settings = client_context->getSettingsRef();
if (settings[Setting::throw_if_no_data_to_insert])
Expand Down
36 changes: 36 additions & 0 deletions tests/test_insert_error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import unittest
import shutil
import os
from chdb import session

test_dir = ".test_insert_error"

class TestInsertErrorHandling(unittest.TestCase):
"""Test cases for INSERT query error handling to ensure proper exceptions are thrown."""

def setUp(self) -> None:
shutil.rmtree(test_dir, ignore_errors=True)
self.sess = session.Session(test_dir)
return super().setUp()

def tearDown(self) -> None:
"""Clean up test environment."""
shutil.rmtree(test_dir, ignore_errors=True)
return super().tearDown()

def test_incomplete_insert_values_throws_error(self):
"""Test that incomplete INSERT VALUES query throws RuntimeError instead of hanging."""

self.sess.query(
"CREATE TABLE test_table(id UInt32, name String, value Float64) ENGINE = Memory"
)

# This should throw an error because VALUES clause is incomplete (no actual values provided)
with self.assertRaises(RuntimeError) as context:
self.sess.query("INSERT INTO test_table (id, name, value) VALUES")


if __name__ == "__main__":
unittest.main()
Loading