From 22498dbec9a6f5b051fe4e2c765c00e44b4a6af5 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 25 Jul 2022 09:34:57 -0700 Subject: [PATCH] Update dao.py --- superset/datasets/dao.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/superset/datasets/dao.py b/superset/datasets/dao.py index 288b45a7b3a18..a538a70c13f8a 100644 --- a/superset/datasets/dao.py +++ b/superset/datasets/dao.py @@ -154,10 +154,10 @@ def update( """ if "columns" in properties: - cls.update_columns(model, properties.pop("columns")) + cls.update_columns(model, properties.pop("columns"), commit=commit) if "metrics" in properties: - cls.update_metrics(model, properties.pop("metrics")) + cls.update_metrics(model, properties.pop("metrics"), commit=commit) return super().update(model, properties, commit=commit) @@ -166,6 +166,7 @@ def update_columns( cls, model: SqlaTable, property_columns: List[Dict[str, Any]], + commit: bool = True, ) -> None: """ Creates/updates and/or deletes a list of columns, based on a @@ -198,11 +199,15 @@ def update_columns( for id_ in {obj.id for obj in model.columns} - seen: DatasetDAO.delete_column(column_by_id[id_], commit=False) + if commit: + db.session.commit() + @classmethod def update_metrics( cls, model: SqlaTable, property_metrics: List[Dict[str, Any]], + commit: bool = True, ) -> None: """ Creates/updates and/or deletes a list of metrics, based on a @@ -235,6 +240,9 @@ def update_metrics( for id_ in {obj.id for obj in model.metrics} - seen: DatasetDAO.delete_column(metric_by_id[id_], commit=False) + if commit: + db.session.commit() + @classmethod def find_dataset_column( cls, dataset_id: int, column_id: int