Explicitly close sqlite connection
The context manage on Connection only commit the connection but it should still be explicitly closed. Closes #13859
This commit is contained in:
@@ -594,8 +594,8 @@ class Database(DatabaseInterface):
|
||||
path = os.path.join(config.get('database', 'path'),
|
||||
database_name + '.sqlite')
|
||||
with sqlite.connect(path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.close()
|
||||
conn.cursor()
|
||||
conn.close()
|
||||
cls._list_cache.clear()
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -171,19 +171,22 @@ def _sqlite_copy(file_, restore=False):
|
||||
finally:
|
||||
database.put_connection(connection, True)
|
||||
|
||||
with Transaction().start(DB_NAME, 0) as transaction, \
|
||||
sqlite.connect(file_) as conn2:
|
||||
with Transaction().start(DB_NAME, 0) as transaction:
|
||||
conn1 = transaction.connection
|
||||
if restore:
|
||||
conn2, conn1 = conn1, conn2
|
||||
if hasattr(conn1, 'backup'):
|
||||
conn1.backup(conn2)
|
||||
else:
|
||||
try:
|
||||
import sqlitebck
|
||||
except ImportError:
|
||||
return False
|
||||
sqlitebck.copy(conn1, conn2)
|
||||
with sqlite.connect(file_) as conn2:
|
||||
if restore:
|
||||
in_, out = conn2, conn1
|
||||
else:
|
||||
in_, out = conn1, conn2
|
||||
if hasattr(in_, 'backup'):
|
||||
in_.backup(out)
|
||||
else:
|
||||
try:
|
||||
import sqlitebck
|
||||
except ImportError:
|
||||
return False
|
||||
sqlitebck.copy(in_, out)
|
||||
conn2.close()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user