diff --git a/src/metabase/api/table.clj b/src/metabase/api/table.clj index c1e69d422d64d8faf1548519642b4864af6dd335..3c749bd00dff56c4f3ba37c1a72c2d65fccc1bdf 100644 --- a/src/metabase/api/table.clj +++ b/src/metabase/api/table.clj @@ -130,12 +130,12 @@ (-> resp (assoc :dimension_options dimension-options-for-response) (update :fields (fn [fields] - (mapv (fn [{:keys [base_type] :as field}] + (mapv (fn [{:keys [base_type min_value max_value] :as field}] (assoc field :dimension_options (cond - (isa? base_type :type/Number) + (and min_value max_value (isa? base_type :type/Number)) numeric-dimension-indexes (isa? base_type :type/DateTime) diff --git a/test/metabase/api/table_test.clj b/test/metabase/api/table_test.clj index 911be3d589261ebf496b86964c0b11c2818d8e99..498d3579af174d9f42b1e316404dbbfa41731734 100644 --- a/test/metabase/api/table_test.clj +++ b/test/metabase/api/table_test.clj @@ -20,7 +20,9 @@ [metabase.test.data [dataset-definitions :as defs] [users :refer :all]] - [toucan.hydrate :as hydrate] + [toucan + [db :as db] + [hydrate :as hydrate]] [toucan.util.test :as tt])) (resolve-private-vars metabase.models.table pk-field-id) @@ -485,6 +487,7 @@ :created_at $}))}))}]) ((user->client :rasta) :get 200 (format "table/%d/fks" (id :users)))) +;; Ensure dimensions options are sorted numerically, but returned as strings (expect (map str (sort (map #(Long/parseLong %) (var-get datetime-dimension-indexes)))) (var-get datetime-dimension-indexes)) @@ -492,3 +495,16 @@ (expect (map str (sort (map #(Long/parseLong %) (var-get numeric-dimension-indexes)))) (var-get numeric-dimension-indexes)) + +;; Numeric fields without min/max values should not have binning strategies +(expect + [] + (let [{:keys [min_value max_value]} (Field (id :categories :id))] + (try + (db/update! Field (id :categories :id) :min_value nil :max_value nil) + (-> ((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :categories))) + (get-in [:fields]) + first + :dimension_options) + (finally + (db/update! Field (id :categories :id) :min_value min_value :max_value max_value)))))