From 6714af804270ee33479fb0caa185a5c5eeec4479 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Tue, 22 May 2018 15:03:30 -0700 Subject: [PATCH] Use maybe_get more Some suggestions in the review of the related change: * use maybe_get in another obvious place * make maybe_gets test assertions stronger Related-Change-Id: Ifd54d76ab1a5a9d82848f3cae89c3e53134aa129 Change-Id: I751f1086d885c18d938f18e8afe1dd0e9c0c57e5 --- swift/container/backend.py | 5 +---- test/unit/common/test_db.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/swift/container/backend.py b/swift/container/backend.py index f61ee77706..7599918da7 100644 --- a/swift/container/backend.py +++ b/swift/container/backend.py @@ -888,11 +888,8 @@ class ContainerBroker(DatabaseBroker): def _populate_instance_cache(self, conn=None): # load cached instance attributes from the database if necessary if self.container is None: - if conn: + with self.maybe_get(conn) as conn: self._do_get_info_query(conn) - else: - with self.get() as conn: - self._do_get_info_query(conn) def _get_alternate_object_stats(self): state = self.get_db_state() diff --git a/test/unit/common/test_db.py b/test/unit/common/test_db.py index 0853f06878..3df59f2957 100644 --- a/test/unit/common/test_db.py +++ b/test/unit/common/test_db.py @@ -618,7 +618,7 @@ class TestExampleBroker(unittest.TestCase): with broker.get() as other_conn: self.assertEqual(broker.conn, None) with broker.maybe_get(other_conn) as identity_conn: - self.assertEqual(other_conn, identity_conn) + self.assertIs(other_conn, identity_conn) self.assertEqual(broker.conn, None) self.assertEqual(broker.conn, None) self.assertEqual(broker.conn, conn)