Skip to content

Commit a5f2e03

Browse files
committed
Allow passing in UUID as property
1 parent 98d2d4c commit a5f2e03

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

posthog/test/utils.py

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

56
from dateutil.tz import tzutc
@@ -50,6 +51,9 @@ def test_clean(self):
5051
utils.clean(combined)
5152
self.assertEqual(combined.keys(), pre_clean_keys)
5253

54+
# test UUID separately, as the UUID object doesn't equal its string representation according to Python
55+
self.assertEqual(utils.clean(UUID('12345678123456781234567812345678')), '12345678-1234-5678-1234-567812345678')
56+
5357
def test_clean_with_dates(self):
5458
dict_with_dates = {
5559
'birthdate': date(1980, 1, 1),

posthog/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dateutil.tz import tzlocal, tzutc
22
from datetime import date, datetime
33
from decimal import Decimal
4+
from uuid import UUID
45
import logging
56
import numbers
67

@@ -47,6 +48,8 @@ def remove_trailing_slash(host):
4748
def clean(item):
4849
if isinstance(item, Decimal):
4950
return float(item)
51+
if isinstance(item, UUID):
52+
return str(item)
5053
elif isinstance(item, (six.string_types, bool, numbers.Number, datetime,
5154
date, type(None))):
5255
return item

0 commit comments

Comments
 (0)