Fixing UUID coerce function for unicode non uuid form

If we use non uuid unicode user id in py27 env,
unicode error pop up when function is called.

Closes-bug: #1760918

Change-Id: Ic6b6308fb1960ec40407e6efde30137b64543e72
This commit is contained in:
Seyeong Kim 2018-03-29 10:03:51 -07:00
parent d1c9160a8b
commit b1d0b5d886
2 changed files with 9 additions and 3 deletions

View File

@ -352,7 +352,7 @@ class UUID(StringPattern):
# like 'error' for this warning.
warnings.filterwarnings(action="once", append=True)
try:
uuid.UUID(str(value))
uuid.UUID(u"%s" % value)
except Exception:
# This is to ensure no breaking behaviour for current
# users
@ -363,9 +363,11 @@ class UUID(StringPattern):
"code to input valid UUIDs or accept "
"ValueErrors for invalid UUIDs. See "
"https://docs.openstack.org/oslo.versionedobjects/latest/reference/fields.html#oslo_versionedobjects.fields.UUIDField " # noqa
"for further details" % value, FutureWarning)
"for further details" %
repr(value).encode('utf8'),
FutureWarning)
return str(value)
return u"%s" % value
class MACAddress(StringPattern):

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -285,6 +286,9 @@ class TestUUID(TestField):
('da66a411-af0e-4829-9b67-475017ddz152',
'da66a411-af0e-4829-9b67-475017ddz152'),
('fake_uuid', 'fake_uuid'),
(u'fake_uāid', u'fake_uāid'),
(b'fake_u\xe1id'.decode('latin_1'),
b'fake_u\xe1id'.decode('latin_1')),
('1', '1'),
(1, '1')
]