Skip to content

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

Filter out stub databases (#75401)

Alexander Polyankinf3dcaa059fc0
diff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.clj
index 86f22c23bb4..c0c1be9882e 100644
--- a/src/metabase/warehouses_rest/api.clj
+++ b/src/metabase/warehouses_rest/api.clj
@@ -335,6 +335,7 @@
:is-superuser? (mi/superuser?)
:is-data-analyst? api/*is-data-analyst?*}
base-where [:and
+ [:= :is_stub false]
(when-not include-analytics?
[:= :is_audit false])
(if filter-on-router-database-id
diff --git a/test/metabase/warehouses_rest/api_test.clj b/test/metabase/warehouses_rest/api_test.clj
index bc3868a828e..a8e7f6b6d9c 100644
--- a/test/metabase/warehouses_rest/api_test.clj
+++ b/test/metabase/warehouses_rest/api_test.clj
@@ -208,6 +208,15 @@
:specific-errors {:include ["should be either \"tables\" or \"tables.fields\", received: \"schemas\""]}}
(mt/user-http-request :lucky :get 400 (format "database/%d?include=schemas" (mt/id))))))))
+(deftest ^:parallel get-database-stub-test
+ (testing "GET /api/database"
+ (testing "A stub database should not be included in the response"
+ (mt/with-temp [:model/Database {db-id-1 :id} {:is_stub true}
+ :model/Database {db-id-2 :id} {:is_stub false}]
+ (let [{databases :data} (mt/user-http-request :lucky :get 200 "database")]
+ (is (nil? (m/find-first #(= (:id %) db-id-1) databases)))
+ (is (some? (m/find-first #(= (:id %) db-id-2) databases))))))))
+
(deftest get-database-legacy-no-self-service-test
(testing "GET /api/database/:id"
(testing "A database can be fetched even if one table has legacy-no-self-service permissions"