Add hasattr checks to prevent faulty __del__.

This commit is contained in:
voussoir 2018-03-13 02:20:17 -07:00
parent 5b310e6d7c
commit b89da5dec2

View file

@ -706,7 +706,13 @@ class PDBSQLMixin:
self.savepoints = []
def close(self):
# Wrapped in hasattr because if the object fails __init__, Python will
# still call __del__ and thus close(), even though the attributes
# we're trying to clean up never got set.
if hasattr(self, 'sql'):
self.sql.close()
if hasattr(self, 'ephemeral'):
if self.ephemeral:
self.ephemeral_directory.cleanup()