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):