From 46b996bf2aa59a69406f0bf0877043fac91eca0b Mon Sep 17 00:00:00 2001
From: Simon Belak <simon@metabase.com>
Date: Fri, 4 May 2018 00:26:45 +0200
Subject: [PATCH] Add fallback to GenericTable

---
 src/metabase/automagic_dashboards/core.clj       |  2 +-
 test/metabase/automagic_dashboards/core_test.clj | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/metabase/automagic_dashboards/core.clj b/src/metabase/automagic_dashboards/core.clj
index b479ead6b76..87c8c89baf2 100644
--- a/src/metabase/automagic_dashboards/core.clj
+++ b/src/metabase/automagic_dashboards/core.clj
@@ -428,7 +428,7 @@
    Most specific is defined as entity type specification the longest ancestor
    chain."
   [rules {:keys [source entity]}]
-  (let [table-type (:entity_type source)]
+  (let [table-type (or (:entity_type source) :entity/GenericTable)]
     (->> rules
          (filter (fn [{:keys [applies_to]}]
                    (let [[entity-type field-type] applies_to]
diff --git a/test/metabase/automagic_dashboards/core_test.clj b/test/metabase/automagic_dashboards/core_test.clj
index 8e79c3634f5..bc4db454390 100644
--- a/test/metabase/automagic_dashboards/core_test.clj
+++ b/test/metabase/automagic_dashboards/core_test.clj
@@ -53,6 +53,17 @@
        (#'magic/matching-rules (rules/load-rules "table"))
        (map (comp first :applies_to))))
 
+;; Test fallback to GenericTable
+(expect
+  [:entity/GenericTable :entity/*]
+  (->> (-> (data/id :users)
+           Table
+           (assoc :entity_type nil)
+           (#'magic/->root))
+       (#'magic/matching-rules (rules/load-rules "table"))
+       (map (comp first :applies_to))))
+
+
 (defn- collect-urls
   [dashboard]
   (->> dashboard
-- 
GitLab