From 840b29499a0b83acea77ee23461ab64f294b2fb5 Mon Sep 17 00:00:00 2001 From: Itai Shirav Date: Thu, 13 Jun 2019 08:58:39 +0300 Subject: [PATCH] UUIDField compatibility with Python 3 --- src/infi/clickhouse_orm/fields.py | 4 +++- tests/test_uuid_fields.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index e864e5f..25ae554 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -461,8 +461,10 @@ class UUIDField(Field): def to_python(self, value, timezone_in_use): if isinstance(value, UUID): return value + elif isinstance(value, binary_type): + return UUID(bytes=value) elif isinstance(value, string_types): - return UUID(bytes=value) if len(value) == 16 else UUID(value) + return UUID(value) elif isinstance(value, integer_types): return UUID(int=value) elif isinstance(value, tuple): diff --git a/tests/test_uuid_fields.py b/tests/test_uuid_fields.py index 247b757..37bee2c 100644 --- a/tests/test_uuid_fields.py +++ b/tests/test_uuid_fields.py @@ -28,7 +28,7 @@ class UUIDFieldsTest(unittest.TestCase): '{12345678-1234-5678-1234-567812345678}', '12345678123456781234567812345678', 'urn:uuid:12345678-1234-5678-1234-567812345678', - '\x12\x34\x56\x78'*4, + b'\x12\x34\x56\x78'*4, (0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678), 0x12345678123456781234567812345678, UUID(int=0x12345678123456781234567812345678),