Skip to content

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

Fix is_personal hydration on instances with no Personal Collections (#83130)

bryanba78bac461c0
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.clj
index f0fbbc34d44..cb988a766a4 100644
--- a/src/metabase/collections/models/collection.clj
+++ b/src/metabase/collections/models/collection.clj
@@ -811,7 +811,7 @@
location-is-personal (fn [location]
(boolean
(and (string? location)
- (personal-collection-ids (first (location-path->ids location))))))]
+ (contains? personal-collection-ids (first (location-path->ids location))))))]
(map (fn [{:keys [location personal_owner_id] :as coll}]
(if (some? coll)
(assoc coll :is_personal (or (some? personal_owner_id)
diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.clj
index fdbe41efd75..663547f3125 100644
--- a/test/metabase/collections/models/collection_test.clj
+++ b/test/metabase/collections/models/collection_test.clj
@@ -1331,6 +1331,15 @@
(is (= nil (t2/hydrate nil :is_personal)))
(is (= [nil true] (map :is_personal (t2/hydrate [nil (t2/select-one :model/Collection personal-coll)] :is_personal)))))))))))
+(deftest hydrate-is-personal-without-any-personal-collections-test
+ (testing "batched hydration works on a fresh instance where no Personal Collection has been created yet"
+ (mt/with-empty-h2-app-db!
+ (let [ids (t2/insert-returning-pks! :model/Collection [{:name "A" :location "/"}
+ {:name "B" :location "/"}])]
+ (is (= [false false]
+ (map :is_personal (t2/hydrate (t2/select :model/Collection :id [:in ids] {:order-by [:id]})
+ :is_personal))))))))
+
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Moving Collections "Across the Boundary" |
;;; +----------------------------------------------------------------------------------------------------------------+