Add hasattr checks to prevent faulty __del__.
This commit is contained in:
parent
5b310e6d7c
commit
b89da5dec2
1 changed files with 9 additions and 3 deletions
|
@ -706,9 +706,15 @@ class PDBSQLMixin:
|
||||||
self.savepoints = []
|
self.savepoints = []
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.sql.close()
|
# Wrapped in hasattr because if the object fails __init__, Python will
|
||||||
if self.ephemeral:
|
# still call __del__ and thus close(), even though the attributes
|
||||||
self.ephemeral_directory.cleanup()
|
# 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()
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
while len(self.on_commit_queue) > 0:
|
while len(self.on_commit_queue) > 0:
|
||||||
|
|
Loading…
Reference in a new issue