37 lines
1.6 KiB
Diff
37 lines
1.6 KiB
Diff
# UNDF: UNDF-2026-000000817
|
|
# UNDF: (leave blank)
|
|
# superset-0003: import_datasource metric/column dedup O(N^2) list rebuild
|
|
# CWE-407: `not in [m.metric_name for m in datasource.metrics]` rebuilds list each iteration
|
|
# Fix: build sets of existing names before loop for O(1) lookup
|
|
--- a/superset/commands/dataset/importers/v0.py
|
|
+++ b/superset/commands/dataset/importers/v0.py
|
|
@@ -161,6 +161,8 @@
|
|
db.session.add(datasource)
|
|
db.session.flush()
|
|
|
|
+ existing_metric_names = {m.metric_name for m in datasource.metrics}
|
|
+ existing_column_names = {c.column_name for c in datasource.columns}
|
|
for metric in i_datasource.metrics:
|
|
new_m = metric.copy()
|
|
new_m.table_id = datasource.id
|
|
@@ -170,7 +172,9 @@
|
|
i_datasource.full_name,
|
|
)
|
|
imported_m = import_metric(new_m)
|
|
- if imported_m.metric_name not in [m.metric_name for m in datasource.metrics]:
|
|
+ if imported_m.metric_name not in existing_metric_names:
|
|
datasource.metrics.append(imported_m)
|
|
+ existing_metric_names.add(imported_m.metric_name)
|
|
|
|
for column in i_datasource.columns:
|
|
new_c = column.copy()
|
|
@@ -182,7 +186,9 @@
|
|
i_datasource.full_name,
|
|
)
|
|
imported_c = import_column(new_c)
|
|
- if imported_c.column_name not in [c.column_name for c in datasource.columns]:
|
|
+ if imported_c.column_name not in existing_column_names:
|
|
datasource.columns.append(imported_c)
|
|
+ existing_column_names.add(imported_c.column_name)
|
|
db.session.flush()
|
|
return datasource.id
|