diff --git a/src/metabase/automagic_dashboards/core.clj b/src/metabase/automagic_dashboards/core.clj index b479ead6b762baede773c8d2c4d80984fdebcc3d..33eebda0012c42a9761ef2709d3d2c3f657caf7d 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] @@ -768,9 +768,7 @@ (let [rules (rules/load-rules "table")] (->> (apply db/select Table (cond-> [:db_id (u/get-id database) - :visibility_type nil - :entity_type [:not= nil]] ; only consider tables that have alredy - ; been analyzed + :visibility_type nil] schema (concat [:schema schema]))) (filter mi/can-read?) (map enhanced-table-stats) diff --git a/test/metabase/automagic_dashboards/core_test.clj b/test/metabase/automagic_dashboards/core_test.clj index 8e79c3634f5861a50725a5d4ef97da3edd7c3f72..958899fbb09cbc90dc111658fd611695e8e68d0a 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 @@ -195,34 +206,20 @@ (expect - [true true] - (tt/with-temp* [Table [{table-id :id}]] - (with-rasta - (with-dashboard-cleanup - (let [table (Table table-id) - not-analyzed-result (automagic-analysis table {}) - analyzed-result (-> table - (assoc :entity_type :entity/GenericTable) - (automagic-analysis {}))] - [(nil? not-analyzed-result) (some? analyzed-result)]))))) + 3 + (with-rasta + (->> (Database (data/id)) candidate-tables first :tables count))) +;; /candidates should work with unanalyzed tables (expect + 1 (tt/with-temp* [Database [{db-id :id}] Table [{table-id :id} {:db_id db-id}] Field [{} {:table_id table-id}] Field [{} {:table_id table-id}]] (with-rasta (with-dashboard-cleanup - (let [database (Database db-id) - not-analyzed-count (count (candidate-tables database))] - (db/update! Table table-id :entity_type :entity/GenericTable) - (= (inc not-analyzed-count) (count (candidate-tables database)))))))) - - -(expect - 3 - (with-rasta - (->> (Database (data/id)) candidate-tables first :tables count))) + (count (candidate-tables (Database db-id))))))) ;; Identity