Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit b194fec

Browse files
committed
Merge branch '335-uuid'
2 parents 6b6d31c + 58676ac commit b194fec

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

cassandra/cqlengine/columns.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from copy import deepcopy, copy
1616
from datetime import date, datetime
1717
import logging
18-
import re
1918
import six
2019
import warnings
2120

@@ -518,18 +517,19 @@ class UUID(Column):
518517
"""
519518
db_type = 'uuid'
520519

521-
re_uuid = re.compile(r'[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}')
522-
523520
def validate(self, value):
524521
val = super(UUID, self).validate(value)
525522
if val is None:
526523
return
527524
from uuid import UUID as _UUID
528525
if isinstance(val, _UUID):
529526
return val
530-
if isinstance(val, six.string_types) and self.re_uuid.match(val):
531-
return _UUID(val)
532-
raise ValidationError("{} {} is not a valid uuid".format(self.column_name, value))
527+
if isinstance(val, six.string_types):
528+
try:
529+
return _UUID(val)
530+
except ValueError:
531+
raise ValidationError("{} {} is not a valid uuid".format(
532+
self.column_name, value))
533533

534534
def to_python(self, value):
535535
return self.validate(value)

tests/integration/cqlengine/columns/test_validation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ def test_uuid_str_no_dashes(self):
240240
t1 = self.UUIDTest.get(test_id=1)
241241
assert a_uuid == t1.a_uuid
242242

243+
def test_uuid_with_upcase(self):
244+
a_uuid = uuid4()
245+
val = str(a_uuid).upper()
246+
t0 = self.UUIDTest.create(test_id=0, a_uuid=val)
247+
t1 = self.UUIDTest.get(test_id=0)
248+
assert a_uuid == t1.a_uuid
249+
243250
class TestTimeUUID(BaseCassEngTestCase):
244251
class TimeUUIDTest(Model):
245252

0 commit comments

Comments
 (0)