Skip to content

Commit 1d6a6b3

Browse files
authored
feat: support uuid for http protocol (xzkostyan#327)
* feat: support uuid for http protocol The `Escaper.escape` method curently doesn't support `uuid.UUID` but it probably should since the other protocols support sending uuid. This pr adds uuid to the escaper case. * fix: tests
1 parent f9267b0 commit 1d6a6b3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clickhouse_sqlalchemy/drivers/http/escaper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import date, datetime
22
from decimal import Decimal
33
import enum
4+
import uuid
45

56

67
class Escaper(object):
@@ -49,6 +50,9 @@ def escape_datetime64(self, item):
4950
def escape_decimal(self, item):
5051
return float(item)
5152

53+
def escape_uuid(self, item):
54+
return str(item)
55+
5256
def escape_item(self, item):
5357
if item is None:
5458
return 'NULL'
@@ -75,5 +79,7 @@ def escape_item(self, item):
7579
) + "}"
7680
elif isinstance(item, enum.Enum):
7781
return self.escape_string(item.name)
82+
elif isinstance(item, uuid.UUID):
83+
return self.escape_uuid(item)
7884
else:
7985
raise Exception("Unsupported object {}".format(item))

tests/drivers/http/test_escaping.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from decimal import Decimal
22
from datetime import date
3+
import uuid
34

45
from sqlalchemy import Column, literal
56

@@ -29,6 +30,10 @@ def test_escaper(self):
2930
self.assertEqual(e.escape([10.0]), '[10.0]')
3031
self.assertEqual(e.escape([date(2017, 1, 2)]), "['2017-01-02']")
3132
self.assertEqual(e.escape(dict(x=10, y=20)), {'x': 10, 'y': 20})
33+
self.assertEqual(
34+
e.escape([uuid.UUID("ef3e3d4b-c782-4993-83fc-894ff0aba8ff")]),
35+
'[ef3e3d4b-c782-4993-83fc-894ff0aba8ff]'
36+
)
3237
with self.assertRaises(Exception) as ex:
3338
e.escape([object()])
3439

0 commit comments

Comments
 (0)