diff --git a/troveclient/tests/test_base.py b/troveclient/tests/test_base.py index e3e89707..bc409c26 100644 --- a/troveclient/tests/test_base.py +++ b/troveclient/tests/test_base.py @@ -375,6 +375,10 @@ class FindResourceTestCase(testtools.TestCase): output = utils.find_resource(self.manager, 'entity_three') 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): def setUp(self): diff --git a/troveclient/utils.py b/troveclient/utils.py index f4db7420..28096a75 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -214,10 +214,12 @@ def find_resource(manager, name_or_id): """Helper for the _find_* methods.""" # first try to get entity as integer id - # if the 'id' starts with '0' don't treat it as an int - if isinstance(name_or_id, int) or ( - name_or_id.isdigit() and not name_or_id.startswith('0')): - name_or_id = int(name_or_id) + # When the 'name_or_id' is int, covert it to string. + # Reason is that manager cannot find instance when name_or_id + # is integer and instance name is digital. + # 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): name_or_id = encodeutils.safe_decode(name_or_id)