This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new f5deda78641 fix(dataset): copy catalog field when duplicating a 
BigQuery dataset (#41106)
f5deda78641 is described below

commit f5deda7864102cc0cb27e385856c4750e96d66eb
Author: yousoph <[email protected]>
AuthorDate: Sat Jul 11 15:24:21 2026 -0700

    fix(dataset): copy catalog field when duplicating a BigQuery dataset 
(#41106)
    
    Co-authored-by: Claude Sonnet 4.6 <[email protected]>
    Co-authored-by: Evan Rusackas <[email protected]>
---
 superset/commands/dataset/duplicate.py             | 63 +++++++++++-----------
 .../unit_tests/commands/dataset/test_duplicate.py  | 13 +++++
 2 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/superset/commands/dataset/duplicate.py 
b/superset/commands/dataset/duplicate.py
index 97159163d01..9b122e65ec5 100644
--- a/superset/commands/dataset/duplicate.py
+++ b/superset/commands/dataset/duplicate.py
@@ -75,43 +75,42 @@ class DuplicateDatasetCommand(CreateMixin, BaseCommand):
                 ),
                 status=404,
             )
-        table = SqlaTable(table_name=table_name, editors=editors)
+        table = SqlaTable()
+        table.override(self._base_model)
+        table.table_name = table_name
+        table.editors = editors
         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
         table.is_sqllab_view = True
-        table.sql = self._base_model.sql.strip().strip(";")
+        if table.sql:
+            table.sql = table.sql.strip().strip(";")
         db.session.add(table)
-        cols = []
-        for config_ in self._base_model.columns:
-            column_name = config_.column_name
-            col = TableColumn(
-                column_name=column_name,
-                verbose_name=config_.verbose_name,
-                expression=config_.expression,
-                filterable=True,
-                groupby=True,
-                is_dttm=config_.is_dttm,
-                type=config_.type,
-                description=config_.description,
+        table.columns = [
+            TableColumn(
+                column_name=c.column_name,
+                verbose_name=c.verbose_name,
+                expression=c.expression,
+                filterable=c.filterable,
+                groupby=c.groupby,
+                is_dttm=c.is_dttm,
+                type=c.type,
+                description=c.description,
             )
-            cols.append(col)
-        table.columns = cols
-        mets = []
-        for config_ in self._base_model.metrics:
-            metric_name = config_.metric_name
-            met = SqlMetric(
-                metric_name=metric_name,
-                verbose_name=config_.verbose_name,
-                expression=config_.expression,
-                metric_type=config_.metric_type,
-                description=config_.description,
+            for c in self._base_model.columns
+        ]
+        table.metrics = [
+            SqlMetric(
+                metric_name=m.metric_name,
+                verbose_name=m.verbose_name,
+                expression=m.expression,
+                metric_type=m.metric_type,
+                description=m.description,
+                d3format=m.d3format,
+                currency=m.currency,
+                warning_text=m.warning_text,
+                extra=m.extra,
             )
-            mets.append(met)
-        table.metrics = mets
+            for m in self._base_model.metrics
+        ]
         return table
 
     def validate(self) -> None:
diff --git a/tests/unit_tests/commands/dataset/test_duplicate.py 
b/tests/unit_tests/commands/dataset/test_duplicate.py
index c78dc5d486c..f03b921c949 100644
--- a/tests/unit_tests/commands/dataset/test_duplicate.py
+++ b/tests/unit_tests/commands/dataset/test_duplicate.py
@@ -456,6 +456,8 @@ def test_duplicate_dataset_with_columns_and_metrics() -> 
None:
     mock_column.is_dttm = False
     mock_column.type = "VARCHAR"
     mock_column.description = "Test column"
+    mock_column.filterable = False
+    mock_column.groupby = False
 
     mock_metric = Mock(spec=SqlMetric)
     mock_metric.metric_name = "count"
@@ -463,6 +465,10 @@ def test_duplicate_dataset_with_columns_and_metrics() -> 
None:
     mock_metric.expression = "COUNT(*)"
     mock_metric.metric_type = "count"
     mock_metric.description = "Row count"
+    mock_metric.d3format = ",.2f"
+    mock_metric.currency = None
+    mock_metric.warning_text = "approximate"
+    mock_metric.extra = None
 
     mock_base_model = Mock(spec=SqlaTable)
     mock_base_model.id = 1
@@ -518,7 +524,14 @@ def test_duplicate_dataset_with_columns_and_metrics() -> 
None:
                         # Verify columns were duplicated
                         assert len(result.columns) == 1
                         assert result.columns[0].column_name == "col1"
+                        # Non-default groupby/filterable flags must survive the
+                        # clone rather than being reset to the column defaults.
+                        assert result.columns[0].filterable is False
+                        assert result.columns[0].groupby is False
 
                         # Verify metrics were duplicated
                         assert len(result.metrics) == 1
                         assert result.metrics[0].metric_name == "count"
+                        # Formatting/metadata fields must survive the clone 
too.
+                        assert result.metrics[0].d3format == ",.2f"
+                        assert result.metrics[0].warning_text == "approximate"

Reply via email to