From 568fcd2107259807b72936b6a784d4ea973b5151 Mon Sep 17 00:00:00 2001
From: Ryan Senior <ryan@metabase.com>
Date: Wed, 14 Jun 2017 11:10:37 -0500
Subject: [PATCH] Fields without min/max data should not include dimension
 options

---
 src/metabase/api/table.clj       |  4 ++--
 test/metabase/api/table_test.clj | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/metabase/api/table.clj b/src/metabase/api/table.clj
index c1e69d422d6..3c749bd00df 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 911be3d5892..498d3579af1 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)))))
-- 
GitLab