Skip to content

Commit 105d643

Browse files
committed
close method on connections
1 parent 65d4da5 commit 105d643

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

qiita_core/util.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,7 @@ def setUp(self):
8080
@reset_test_database
8181
def tearDown(self):
8282
super(DecoratedClass, self).tearDown()
83-
if self.conn_handler._user_conn is not None:
84-
self.conn_handler._user_conn.close()
85-
86-
if self.conn_handler._admin_conn is not None:
87-
self.conn_handler._admin_conn.close()
88-
89-
if self.conn_handler._admin_nodb_conn is not None:
90-
self.conn_handler._admin_nodb_conn.close()
83+
self.conn_handler.close()
9184

9285
return DecoratedClass
9386
return class_modifier

qiita_db/environment_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def drop_environment(ask_for_confirmation):
265265
do_drop = True
266266

267267
if do_drop:
268+
SQLConnectionHandler.close()
268269
admin_conn = SQLConnectionHandler(admin='admin_without_database')
269270
admin_conn.set_autocommit('on')
270271
admin_conn.execute('DROP DATABASE %s' % qiita_config.database)

qiita_db/sql_connection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ def _open_connection(self):
223223
else:
224224
self._connection = getattr(SQLConnectionHandler, self._conn_attr)
225225

226+
@staticmethod
227+
def close():
228+
if SQLConnectionHandler._user_conn is not None:
229+
SQLConnectionHandler._user_conn.close()
230+
231+
if SQLConnectionHandler._admin_conn is not None:
232+
SQLConnectionHandler._admin_conn.close()
233+
234+
if SQLConnectionHandler._admin_nodb_conn is not None:
235+
SQLConnectionHandler._admin_nodb_conn.close()
236+
226237
@contextmanager
227238
def get_postgres_cursor(self):
228239
""" Returns a Postgres cursor

0 commit comments

Comments
 (0)