Skip to content

Commit

Permalink
Fix input_format_null_as_default for UUID #401
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Dec 8, 2023
1 parent e90b34d commit f088802
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/uuidcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def before_write_items(self, items, nulls_map=None):

try:
if not isinstance(item, UUID):
item = UUID(item)
item = UUID(int=item) if item is null_value else UUID(item)

except ValueError:
raise errors.CannotParseUuidError(
Expand Down
17 changes: 17 additions & 0 deletions tests/columns/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ def test_nullable(self):

inserted = self.client.execute(query)
self.assertEqual(inserted, data)

def test_input_format_null_as_default(self):
with self.create_table('a UUID'):
self.client.execute(
'INSERT INTO test (a) VALUES', [(None, )],
settings={'input_format_null_as_default': True}
)

query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(inserted,
'00000000-0000-0000-0000-000000000000\n')

inserted = self.client.execute(query)
self.assertEqual(inserted, [
(UUID(int=0), )
])

0 comments on commit f088802

Please sign in to comment.