-
Notifications
You must be signed in to change notification settings - Fork 64
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
Include the column name in the error message for an unexpected NULL #397
Changes from 1 commit
9fa0ba7
e065f05
527fde4
35115e6
279e1a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,13 @@ def array_type(size: int, signed: bool): | |
return code if signed else code.upper() | ||
|
||
|
||
def write_array(code: str, column: Sequence, dest: MutableSequence): | ||
def write_array(code: str, column: Sequence, dest: MutableSequence, ctx): | ||
""" | ||
Write a column of native Python data matching the array.array code | ||
:param code: Python array.array code matching the column data type | ||
:param column: Column of native Python values | ||
:param dest: Destination byte buffer | ||
:param ctx: The InsertContext | ||
""" | ||
if len(column) and not isinstance(column[0], (int, float)): | ||
if code in ('f', 'F', 'd', 'D'): | ||
|
@@ -54,8 +55,8 @@ def write_array(code: str, column: Sequence, dest: MutableSequence): | |
buff = struct.Struct(f'<{len(column)}{code}') | ||
dest += buff.pack(*column) | ||
except (TypeError, OverflowError, struct.error) as ex: | ||
raise DataError('Unable to create Python array. This is usually caused by trying to insert None ' + | ||
'values into a ClickHouse column that is not Nullable') from ex | ||
raise ctx.make_data_error('Unable to create Python array. This is usually caused by trying to insert None ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the only error I really needed improving, but I modified the other places where DataError could be raised too, in string.py |
||
'values into a ClickHouse column that is not Nullable') from ex | ||
|
||
|
||
def write_uint64(value: int, dest: MutableSequence): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
from clickhouse_connect.driver.ctypes import data_conv | ||
from clickhouse_connect.driver.context import BaseQueryContext | ||
from clickhouse_connect.driver.options import np, pd, pd_time_test | ||
from clickhouse_connect.driver.exceptions import ProgrammingError | ||
from clickhouse_connect.driver.exceptions import ProgrammingError, DataError | ||
|
||
if TYPE_CHECKING: | ||
from clickhouse_connect.datatypes.base import ClickHouseType | ||
|
@@ -53,6 +53,7 @@ def __init__(self, | |
self.block_row_count = DEFAULT_BLOCK_BYTES | ||
self.data = data | ||
self.insert_exception = None | ||
self._column_name = None | ||
|
||
@property | ||
def empty(self) -> bool: | ||
|
@@ -198,3 +199,12 @@ def _convert_numpy(self, np_array): | |
data[ix] = data[ix].tolist() | ||
self.column_oriented = True | ||
return data | ||
|
||
def start_column(self, name: str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets called during the insert to tell us what the current column being inserted is, so I store its name here so we have it if we run into an error during inserting that column |
||
super().start_column(name) | ||
self._column_name = name | ||
|
||
def make_data_error(self, error_message: str) -> DataError: | ||
if self._column_name is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's where we use the column name that was stored by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not possible, so it's safe to remove the None check. |
||
return DataError(f"Failed to write column '{self._column_name}': {error_message}") | ||
return DataError(error_message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add the ctx Type here too?