From e9a5fdbad1d7573ab4fe4bca654403465cec206b Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Wed, 26 Jul 2017 18:23:05 -0400 Subject: [PATCH] Use a more pro-active approach to identify an uninitialized db proxy. --- data/database.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/data/database.py b/data/database.py index 1482a4ee1..5933005f7 100644 --- a/data/database.py +++ b/data/database.py @@ -323,18 +323,13 @@ get_epoch_timestamp_ms = lambda: int(time.time() * 1000) def close_db_filter(_): - try: - if not db.is_closed(): - logger.debug('Disconnecting from database.') - db.close() + if db.obj is not None and not db.is_closed(): + logger.debug('Disconnecting from database.') + db.close() - if read_slave.obj is not None and not read_slave.is_closed(): - logger.debug('Disconnecting from read slave.') - read_slave.close() - except AttributeError: - # If the database is closed between the time we check on line 309 and db.close() is called on - # 311, then an AttributeError will be raised. Simply eat this exception and continue onward. - pass + if read_slave.obj is not None and not read_slave.is_closed(): + logger.debug('Disconnecting from read slave.') + read_slave.close() class QuayUserField(ForeignKeyField):