chore: Cleanup database sessions (#10427)

Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
John Bodley
2020-07-30 23:07:56 -07:00
committed by GitHub
parent 7ff1757448
commit 7645fc85c3
39 changed files with 488 additions and 637 deletions

View File

@@ -46,20 +46,19 @@ class TestImportExport(SupersetTestCase):
def delete_imports(cls):
with app.app_context():
# Imported data clean up
session = db.session
for slc in session.query(Slice):
for slc in db.session.query(Slice):
if "remote_id" in slc.params_dict:
session.delete(slc)
for dash in session.query(Dashboard):
db.session.delete(slc)
for dash in db.session.query(Dashboard):
if "remote_id" in dash.params_dict:
session.delete(dash)
for table in session.query(SqlaTable):
db.session.delete(dash)
for table in db.session.query(SqlaTable):
if "remote_id" in table.params_dict:
session.delete(table)
for datasource in session.query(DruidDatasource):
db.session.delete(table)
for datasource in db.session.query(DruidDatasource):
if "remote_id" in datasource.params_dict:
session.delete(datasource)
session.commit()
db.session.delete(datasource)
db.session.commit()
@classmethod
def setUpClass(cls):
@@ -126,9 +125,7 @@ class TestImportExport(SupersetTestCase):
def create_druid_datasource(self, name, id=0, cols_names=[], metric_names=[]):
cluster_name = "druid_test"
cluster = self.get_or_create(
DruidCluster, {"cluster_name": cluster_name}, db.session
)
cluster = self.get_or_create(DruidCluster, {"cluster_name": cluster_name})
params = {"remote_id": id, "database_name": cluster_name}
datasource = DruidDatasource(