Skip to content

Commit 9f74b88

Browse files
committed
Merge pull request #3687 from benred42/3679-UUIDField-validation
Fixed #3679 -- UUID Validation
2 parents 17267bf + c153bcb commit 9f74b88

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

rest_framework/fields.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,11 @@ def to_internal_value(self, data):
769769
try:
770770
if isinstance(data, six.integer_types):
771771
return uuid.UUID(int=data)
772-
else:
772+
elif isinstance(data, six.string_types):
773773
return uuid.UUID(hex=data)
774-
except (ValueError, TypeError):
774+
else:
775+
self.fail('invalid', value=data)
776+
except (ValueError):
775777
self.fail('invalid', value=data)
776778
return data
777779

tests/test_fields.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ class TestUUIDField(FieldValues):
609609
284758210125106368185219588917561929842: uuid.UUID('d63a6fb6-88d5-40c7-a91c-9edf73283072')
610610
}
611611
invalid_inputs = {
612-
'825d7aeb-05a9-45b5-a5b7': ['"825d7aeb-05a9-45b5-a5b7" is not a valid UUID.']
612+
'825d7aeb-05a9-45b5-a5b7': ['"825d7aeb-05a9-45b5-a5b7" is not a valid UUID.'],
613+
(1, 2, 3): ['"(1, 2, 3)" is not a valid UUID.']
613614
}
614615
outputs = {
615616
uuid.UUID('825d7aeb-05a9-45b5-a5b7-05df87923cda'): '825d7aeb-05a9-45b5-a5b7-05df87923cda'

0 commit comments

Comments
 (0)