Merge "Fix show instance with integer name NotFound"
This commit is contained in:
@@ -375,6 +375,10 @@ class FindResourceTestCase(testtools.TestCase):
|
|||||||
output = utils.find_resource(self.manager, 'entity_three')
|
output = utils.find_resource(self.manager, 'entity_three')
|
||||||
self.assertEqual(self.manager.get('4242'), output)
|
self.assertEqual(self.manager.get('4242'), output)
|
||||||
|
|
||||||
|
def test_find_by_int_name(self):
|
||||||
|
output = utils.find_resource(self.manager, 9876)
|
||||||
|
self.assertEqual(self.manager.get('5678'), output)
|
||||||
|
|
||||||
|
|
||||||
class ResourceTest(testtools.TestCase):
|
class ResourceTest(testtools.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@@ -214,10 +214,12 @@ def find_resource(manager, name_or_id):
|
|||||||
"""Helper for the _find_* methods."""
|
"""Helper for the _find_* methods."""
|
||||||
# first try to get entity as integer id
|
# first try to get entity as integer id
|
||||||
|
|
||||||
# if the 'id' starts with '0' don't treat it as an int
|
# When the 'name_or_id' is int, covert it to string.
|
||||||
if isinstance(name_or_id, int) or (
|
# Reason is that manager cannot find instance when name_or_id
|
||||||
name_or_id.isdigit() and not name_or_id.startswith('0')):
|
# is integer and instance name is digital.
|
||||||
name_or_id = int(name_or_id)
|
# Related to bug/1740015.
|
||||||
|
if isinstance(name_or_id, int):
|
||||||
|
name_or_id = six.text_type(name_or_id)
|
||||||
elif sys.version_info <= (3, 0):
|
elif sys.version_info <= (3, 0):
|
||||||
name_or_id = encodeutils.safe_decode(name_or_id)
|
name_or_id = encodeutils.safe_decode(name_or_id)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user