Skip to content

Commit 8e565d0

Browse files
committed
ValidationError for invalid UUID types
Follow-on to apache#335. Fixes issue where non-string or UUID types would return None from UUID.validate. Also removed test that did not do what it purported (previously inserting None for key instead of value, and failing for Validation of UUID and not key).
1 parent b194fec commit 8e565d0

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

cassandra/cqlengine/columns.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,10 @@ def validate(self, value):
528528
try:
529529
return _UUID(val)
530530
except ValueError:
531-
raise ValidationError("{} {} is not a valid uuid".format(
532-
self.column_name, value))
531+
# fall-through to error
532+
pass
533+
raise ValidationError("{} {} is not a valid uuid".format(
534+
self.column_name, value))
533535

534536
def to_python(self, value):
535537
return self.validate(value)
@@ -824,6 +826,8 @@ def validate(self, value):
824826
return
825827
if not isinstance(val, dict):
826828
raise ValidationError('{} {} is not a dict object'.format(self.column_name, val))
829+
if None in val:
830+
raise ValidationError("{} None is not allowed in a map".format(self.column_name))
827831
return {self.key_col.validate(k): self.value_col.validate(v) for k, v in val.items()}
828832

829833
def to_python(self, value):

tests/integration/cqlengine/columns/test_container_columns.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ def test_blind_list_updates_from_none(self):
345345
assert m3.int_list == []
346346

347347
class TestMapModel(Model):
348-
349-
350348
partition = columns.UUID(primary_key=True, default=uuid4)
351349
int_map = columns.Map(columns.Integer, columns.UUID, required=False)
352350
text_map = columns.Map(columns.Text, columns.DateTime, required=False)
@@ -371,11 +369,7 @@ def test_empty_default(self):
371369

372370
def test_add_none_as_map_key(self):
373371
with self.assertRaises(ValidationError):
374-
TestMapModel.create(int_map={None:1})
375-
376-
def test_add_none_as_map_value(self):
377-
with self.assertRaises(ValidationError):
378-
TestMapModel.create(int_map={None:1})
372+
TestMapModel.create(int_map={None: uuid4()})
379373

380374
def test_empty_retrieve(self):
381375
tmp = TestMapModel.create()

0 commit comments

Comments
 (0)