@@ -93,7 +93,13 @@ def duplicate_source_dashboard_datasets
93
93
# duplicate the dataset, renaming to use of suffix as the target_schema
94
94
# reason: there is a bug(or feature) in the SS API where a dataset name must be uniq when duplicating.
95
95
# (note however renaming in the GUI to a dup name works fine)
96
- new_dataset_id = Superset ::Dataset ::Duplicate . new ( source_dataset_id : dataset [ :id ] , new_dataset_name : "#{ dataset [ :datasource_name ] } -#{ target_schema } " ) . perform
96
+ new_dataset_name = "#{ dataset [ :datasource_name ] } -#{ target_schema } "
97
+ existing_datasets = Dataset ::List . new ( title_equals : new_dataset_name , schema_equals : source_dataset . schema ) . result
98
+ if existing_dataset . any?
99
+ new_dataset_id = existing_datasets [ 0 ] [ "id" ] # assuming that we do not name multiple datasets with same name in a single schema
100
+ else
101
+ new_dataset_id = Superset ::Dataset ::Duplicate . new ( source_dataset_id : dataset [ :id ] , new_dataset_name : new_dataset_name ) . perform
102
+ end
97
103
98
104
# keep track of the previous dataset and the matching new dataset_id
99
105
dataset_duplication_tracker << { source_dataset_id : dataset [ :id ] , new_dataset_id : new_dataset_id }
@@ -179,7 +185,7 @@ def new_dashboard
179
185
180
186
# retrieve the datasets that will be duplicated
181
187
def source_dashboard_datasets
182
- @source_dashboard_datasets ||= Superset ::Dashboard ::Datasets ::List . new ( source_dashboard_id ) . datasets_details
188
+ @source_dashboard_datasets ||= Superset ::Dashboard ::Datasets ::List . new ( source_dashboard_id , true ) . datasets_details
183
189
rescue => e
184
190
raise "Unable to retrieve datasets for source dashboard #{ source_dashboard_id } : #{ e . message } "
185
191
end
@@ -255,11 +261,7 @@ def source_dashboard_dataset_ids
255
261
end
256
262
257
263
def source_dashboard_filter_dataset_ids
258
- filters_configuration = JSON . parse ( source_dashboard . result [ 'json_metadata' ] ) [ 'native_filter_configuration' ] || [ ]
259
- return Array . new unless filters_configuration && filters_configuration . any?
260
-
261
- # pull only the filters dataset ids from the dashboard
262
- filters_configuration . map { |c | c [ 'targets' ] } . flatten . compact . map { |c | c [ 'datasetId' ] } . flatten . compact
264
+ @filter_dataset_ids ||= Superset ::Dashboard ::Filters ::List . new ( id ) . perform
263
265
end
264
266
265
267
# Primary Assumption is that all charts datasets on the source dashboard are pointing to the same database schema
0 commit comments