refactor: Ensure Flask framework leverages the Flask-SQLAlchemy session (Phase II) (#26909)

This commit is contained in:
John Bodley
2024-02-14 06:20:15 +13:00
committed by GitHub
parent 827864b939
commit 847ed3f5b0
96 changed files with 656 additions and 730 deletions

View File

@@ -177,7 +177,6 @@ def load_dataset_with_columns() -> Generator[SqlaTable, None, None]:
with app.app_context():
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"], echo=True)
meta = MetaData()
session = db.session
students = Table(
"students",
@@ -196,8 +195,8 @@ def load_dataset_with_columns() -> Generator[SqlaTable, None, None]:
)
column = TableColumn(table_id=dataset.id, column_name="name")
dataset.columns = [column]
session.add(dataset)
session.commit()
db.session.add(dataset)
db.session.commit()
yield dataset
# cleanup
@@ -205,8 +204,8 @@ def load_dataset_with_columns() -> Generator[SqlaTable, None, None]:
if students_table is not None:
base = declarative_base()
# needed for sqlite
session.commit()
db.session.commit()
base.metadata.drop_all(engine, [students_table], checkfirst=True)
session.delete(dataset)
session.delete(column)
session.commit()
db.session.delete(dataset)
db.session.delete(column)
db.session.commit()