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 = [] | ||||
| 
 | ||||
|     def close(self): | ||||
|         self.sql.close() | ||||
|         if self.ephemeral: | ||||
|             self.ephemeral_directory.cleanup() | ||||
|         # 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() | ||||
| 
 | ||||
|     def commit(self): | ||||
|         while len(self.on_commit_queue) > 0: | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue