Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[Params] Always return `[]` for param `/values` requests (#71302)

Braden Shepherdson051c1a6b25ec
diff --git a/src/metabase/parameters/custom_values.clj b/src/metabase/parameters/custom_values.clj
index 157ede25675..9c66ef7b9ab 100644
--- a/src/metabase/parameters/custom_values.clj
+++ b/src/metabase/parameters/custom_values.clj
@@ -124,7 +124,7 @@
(let [mbql-query (values-from-card-query card field-ref opts)
result (some-> mbql-query qp/process-query)
values (get-in result [:data :rows])]
- {:values values
+ {:values (or values [])
;; If the row_count returned = the limit we specified, then it's probably has more than that.
;; If the query has its own limit smaller than *max-rows*, then there's no more values.
:has_more_values (= (:row_count result) *max-rows*)})))
diff --git a/test/metabase/parameters/custom_values_test.clj b/test/metabase/parameters/custom_values_test.clj
index 4dfec47d4f5..34c34c0e3be 100644
--- a/test/metabase/parameters/custom_values_test.clj
+++ b/test/metabase/parameters/custom_values_test.clj
@@ -195,6 +195,21 @@
[:expression {:lib/uuid "00000000-0000-0000-0000-000000000000", :base-type :type/Float} "unit price"]
{:stage-number 0})))))))
+(deftest ^:parallel with-mbql-card-test-7-dangling-value-field
+ (binding [custom-values/*max-rows* 3]
+ (testing ":value_field references MBQL model which no longer returns that column, but has outdated :field_ref that matches it (#71164)"
+ (mt/with-temp
+ [:model/Card card (-> (mt/card-with-source-metadata-for-query
+ (mt/mbql-query people))
+ (assoc :type :question)
+ (assoc-in [:result_metadata 3 :field_ref] [:field 99999 nil]))]
+ (is (= {:values []
+ :has_more_values false}
+ (custom-values/values-from-card
+ card
+ [:field {:lib/uuid "00000000-0000-0000-0000-000000000000", :base-type :type/Text} 99999]
+ {:stage-number 0})))))))
+
(deftest ^:parallel with-native-card-test
(doseq [model? [true false]]
(testing (format "source card is a %s with native question" (if model? "model" "question"))