kgabryje commented on code in PR #30364:
URL: https://github.com/apache/superset/pull/30364#discussion_r1775125877


##########
superset-frontend/src/explore/controlUtils/getControlValuesCompatibleWithDatasource.ts:
##########
@@ -27,50 +27,64 @@ import {
   JsonValue,
   SimpleAdhocFilter,
 } from '@superset-ui/core';
+import { isEmpty } from 'lodash';
 import AdhocMetric from 
'src/explore/components/controls/MetricControl/AdhocMetric';
 
 const isControlValueCompatibleWithDatasource = (
   datasource: Dataset,
   controlState: ControlState,
   value: any,
 ) => {
+  // A datasource might have been deleted, in which case we can't validate
+  // only using the control state since it might have been hydrated with
+  // the wrong options or columns (empty arrays).
   if (controlState.options && typeof value === 'string') {
     if (
-      controlState.options.some(
-        (option: [string | number, string] | { column_name: string }) =>
-          Array.isArray(option)
-            ? option[0] === value
-            : option.column_name === value,
-      )
+      (!isEmpty(controlState.options) &&
+        controlState.options.some(
+          (option: [string | number, string] | { column_name: string }) =>
+            Array.isArray(option)
+              ? option[0] === value
+              : option.column_name === value,
+        )) ||
+      !isEmpty(datasource?.columns)
     ) {
-      return datasource.columns.some(column => column.column_name === value);
+      return datasource.columns.some(
+        (column: Column) => column.column_name === value,
+      );
     }
   }
-  if (
-    controlState.savedMetrics &&
-    isSavedMetric(value) &&
-    controlState.savedMetrics.some(
-      (savedMetric: Metric) => savedMetric.metric_name === value,
-    )
-  ) {
-    return datasource.metrics.some(
-      (metric: Metric) => metric.metric_name === value,
-    );
+  if (controlState.savedMetrics && isSavedMetric(value)) {
+    if (
+      controlState.savedMetrics.some(
+        (savedMetric: Metric) => savedMetric.metric_name === value,
+      ) ||
+      !isEmpty(datasource?.metrics)
+    ) {
+      return datasource.metrics.some(
+        (metric: Metric) => metric.metric_name === value,
+      );
+    }
   }
   if (
     controlState.columns &&
-    (isAdhocMetricSimple(value) || isSimpleAdhocFilter(value)) &&
-    controlState.columns.some(
-      (column: Column) =>
-        column.column_name === (value as AdhocMetric).column?.column_name ||
-        column.column_name === (value as SimpleAdhocFilter).subject,
-    )
+    (isAdhocMetricSimple(value) || isSimpleAdhocFilter(value))
   ) {
-    return datasource.columns.some(
-      (column: Column) =>
-        column.column_name === (value as AdhocMetric).column?.column_name ||
-        column.column_name === (value as SimpleAdhocFilter).subject,
-    );
+    if (

Review Comment:
   same here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to