Skip to content

Commit

Permalink
feat: support uuid for http protocol (#327)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
LemonPy29 authored Aug 5, 2024
1 parent f9267b0 commit 1d6a6b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clickhouse_sqlalchemy/drivers/http/escaper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date, datetime
from decimal import Decimal
import enum
import uuid


class Escaper(object):
Expand Down Expand Up @@ -49,6 +50,9 @@ def escape_datetime64(self, item):
def escape_decimal(self, item):
return float(item)

def escape_uuid(self, item):
return str(item)

def escape_item(self, item):
if item is None:
return 'NULL'
Expand All @@ -75,5 +79,7 @@ def escape_item(self, item):
) + "}"
elif isinstance(item, enum.Enum):
return self.escape_string(item.name)
elif isinstance(item, uuid.UUID):
return self.escape_uuid(item)
else:
raise Exception("Unsupported object {}".format(item))
5 changes: 5 additions & 0 deletions tests/drivers/http/test_escaping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from decimal import Decimal
from datetime import date
import uuid

from sqlalchemy import Column, literal

Expand Down Expand Up @@ -29,6 +30,10 @@ def test_escaper(self):
self.assertEqual(e.escape([10.0]), '[10.0]')
self.assertEqual(e.escape([date(2017, 1, 2)]), "['2017-01-02']")
self.assertEqual(e.escape(dict(x=10, y=20)), {'x': 10, 'y': 20})
self.assertEqual(
e.escape([uuid.UUID("ef3e3d4b-c782-4993-83fc-894ff0aba8ff")]),
'[ef3e3d4b-c782-4993-83fc-894ff0aba8ff]'
)
with self.assertRaises(Exception) as ex:
e.escape([object()])

Expand Down

0 comments on commit 1d6a6b3

Please sign in to comment.