From 09b7a9f74a3f039097766f36b958ad63a61b7054 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 3 Nov 2021 21:35:12 -0400 Subject: [PATCH 1/3] add database id back --- superset-frontend/src/SqlLab/components/ResultSet/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx index 7da6bce1bb7d7..16d1e014b49c6 100644 --- a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx +++ b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx @@ -147,6 +147,7 @@ const ResultSetErrorMessage = styled.div` `; const updateDataset = async ( + dbId: number, datasetId: number, sql: string, columns: Array>, @@ -159,6 +160,7 @@ const updateDataset = async ( sql, columns, owners, + database_id: dbId, }); const data: JsonResponse = await SupersetClient.put({ @@ -272,10 +274,11 @@ export default class ResultSet extends React.PureComponent< }; handleOverwriteDataset = async () => { - const { sql, results } = this.props.query; + const { sql, results, dbId } = this.props.query; const { datasetToOverwrite } = this.state; await updateDataset( + dbId, datasetToOverwrite.datasetId, sql, results.selected_columns.map(d => ({ column_name: d.name })), From 9e26e64b841110b64e9581bdd0acba915804abd3 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Thu, 4 Nov 2021 23:06:02 -0400 Subject: [PATCH 2/3] add condition to verify dataset is being changed --- superset/connectors/sqla/models.py | 3 +-- superset/datasets/dao.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index b653693e7d63a..72fd2156905dc 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -1734,14 +1734,13 @@ def before_update( for attr in ["database_id", "schema", "table_name"]: history = state.get_history(attr, True) - if history.has_changes(): break else: return None if not DatasetDAO.validate_uniqueness( - target.database_id, target.schema, target.table_name + target.database_id, target.schema, target.table_name, target.id ): raise Exception(get_dataset_exist_error_msg(target.full_name)) diff --git a/superset/datasets/dao.py b/superset/datasets/dao.py index 363e89b8b7f43..7e92438d5fcb9 100644 --- a/superset/datasets/dao.py +++ b/superset/datasets/dao.py @@ -85,12 +85,22 @@ def validate_table_exists( return False @staticmethod - def validate_uniqueness(database_id: int, schema: Optional[str], name: str) -> bool: + def validate_uniqueness( + database_id: int, + schema: Optional[str], + name: str, + dataset_id: Optional[int] = None, + ) -> bool: dataset_query = db.session.query(SqlaTable).filter( SqlaTable.table_name == name, SqlaTable.schema == schema, SqlaTable.database_id == database_id, ) + + if dataset_id: + # Validate that the dataset is not referencing itself + dataset_query = dataset_query.filter(SqlaTable.id != dataset_id) + return not db.session.query(dataset_query.exists()).scalar() @staticmethod From ebeb351b29609abbb1b3475cc70777f1aa401cfa Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Tue, 9 Nov 2021 20:33:45 -0500 Subject: [PATCH 3/3] Update superset/datasets/dao.py Co-authored-by: Beto Dealmeida --- superset/datasets/dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/datasets/dao.py b/superset/datasets/dao.py index 7e92438d5fcb9..5d30e655b47d4 100644 --- a/superset/datasets/dao.py +++ b/superset/datasets/dao.py @@ -98,7 +98,7 @@ def validate_uniqueness( ) if dataset_id: - # Validate that the dataset is not referencing itself + # make sure the dataset found is different from the target (if any) dataset_query = dataset_query.filter(SqlaTable.id != dataset_id) return not db.session.query(dataset_query.exists()).scalar()