Skip to content

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

Fix including library sub-collection throws an error in typed schemas (#82513)

Phoomparin Manod7b9a7169883
diff --git a/src/metabase/typed_schemas/db.clj b/src/metabase/typed_schemas/db.clj
index a631188f0a5..27769a18b37 100644
--- a/src/metabase/typed_schemas/db.clj
+++ b/src/metabase/typed_schemas/db.clj
@@ -29,7 +29,7 @@
unscoped), in name then id order."
[card-type :- [:enum :model :question :metric]
database-ids :- [:maybe [:set ::lib.schema.id/database]]
- collection-ids :- [:maybe [:sequential ::lib.schema.id/collection]]]
+ collection-ids :- [:maybe [:set ::lib.schema.id/collection]]]
(t2/select :model/Card
{:where [:and
[:= :type (name card-type)]
diff --git a/test/metabase/typed_schemas/source_test.clj b/test/metabase/typed_schemas/source_test.clj
index b9a772f6073..f5c409dd3d5 100644
--- a/test/metabase/typed_schemas/source_test.clj
+++ b/test/metabase/typed_schemas/source_test.clj
@@ -6,6 +6,7 @@
database."
(:require
[clojure.test :refer :all]
+ [metabase.collections.models.collection :as collection]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.typed-schemas.scope :as scope]
@@ -64,6 +65,27 @@
(source/library-scope source/app-db-source
{:library-collection-refs [{:id (:id plain-collection)}]})))))))
+(deftest metrics-honour-library-collection-scope-test
+ (mt/with-temp [:model/Collection root {:name "Library", :type "library", :location "/"}
+ :model/Collection metrics {:name "Metrics"
+ :type "library-metrics"
+ :location (collection/children-location root)}
+ :model/Collection child {:name "Child"
+ :type "library-metrics"
+ :location (collection/children-location metrics)}
+ :model/Card _metric {:name "Library revenue"
+ :type :metric
+ :collection_id (:id child)}]
+ (mt/with-test-user :crowberto
+ (let [{:keys [metric-collection-ids]}
+ (source/library-scope source/app-db-source
+ {:library-collection-refs [{:id (:id metrics)}]})]
+ (is (= ["libraryRevenue"]
+ (map :key
+ (source/metrics source/app-db-source nil metric-collection-ids))))
+ (is (= []
+ (source/metrics source/app-db-source nil #{})))))))
+
(deftest tables-test
(mt/with-temp [:model/Database db {}
:model/Table table {:db_id (:id db), :name "widgets", :display_name "Widgets", :active true}