Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
Fix bug in Uuid.normalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Dec 1, 2019
1 parent e418303 commit 408bc83
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASES.rst
Expand Up @@ -6,6 +6,7 @@ Releases

*Unreleased*

- Fix bug in ``Uuid.normalize()``.
- Rename ``Constant`` field to ``Literal``. (`#118`_)

.. _#118: https://github.com/rossmacarthur/serde/pull/118
Expand Down
1 change: 1 addition & 0 deletions src/serde/fields.py
Expand Up @@ -1209,6 +1209,7 @@ def normalize(self, value):
if not isinstance(value, uuid.UUID):
input_form = 'int' if isinstance(value, integer_types) else 'hex'
return uuid.UUID(**{input_form: value})
return value


FIELD_CLASS_MAP = {
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fields.py
Expand Up @@ -1155,6 +1155,12 @@ def test_serialize(self):
value = uuid.UUID('2d7026c8-cc58-11e8-bd7a-784f4386978e')
assert field.serialize(value) == '2d7026c8-cc58-11e8-bd7a-784f4386978e'

def test_normalize_uuid(self):
# A Uuid should normalize a uuid.UUID as a uuid.UUID
field = Uuid()
value = uuid.uuid4()
assert field.normalize(value) is value

def test_normalize_str(self):
# A Uuid should normalize a string as a uuid.UUID.
field = Uuid()
Expand Down

0 comments on commit 408bc83

Please sign in to comment.