Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions superset/commands/dataset/duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def run(self) -> Model:
table = SqlaTable(table_name=table_name, owners=owners)
table.database = database
table.schema = self._base_model.schema
table.catalog = self._base_model.catalog
table.template_params = self._base_model.template_params
table.normalize_columns = self._base_model.normalize_columns
table.always_filter_main_dttm = self._base_model.always_filter_main_dttm
Expand Down Expand Up @@ -115,8 +116,14 @@ def validate(self) -> None:
if self._base_model and self._base_model.kind != "virtual":
exceptions.append(DatasourceTypeInvalidError())

if DatasetDAO.find_one_or_none(table_name=duplicate_name):
exceptions.append(DatasetExistsValidationError(table=Table(duplicate_name)))
# Validate uniqueness using the same pattern as CreateDatasetCommand
if database := db.session.query(Database).get(self._base_model.database_id):
catalog = self._base_model.catalog or database.get_default_catalog()

table = Table(duplicate_name, self._base_model.schema, catalog)

if not DatasetDAO.validate_uniqueness(database, table):
exceptions.append(DatasetExistsValidationError(table=table))

try:
owners = self.populate_owners()
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/datasets/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def create_virtual_datasets(self):
[admin.id],
main_db,
"SELECT * from ab_view_menu;",
catalog=main_db.get_default_catalog(),
)
)
yield datasets
Expand Down
Loading
Loading