The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Don't duplicate uploads in admin page (#68077)
Nathan Voxland09d1a5d6300f
diff --git a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj b/enterprise/backend/src/metabase_enterprise/upload_management/api.cljindex 5b726271321..0e4d911bb11 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/api.clj@@ -12,11 +12,11 @@(defn- attached-dwh-tables"Used for adding attached DWH tables to the list of tables visible to the user. In practice these are to manage- google sheets uploads."+ google sheets uploads. Excludes tables with is_upload=true since those are already included in the main query."[](when (premium-features/has-feature? :attached-dwh)(when-let [dw-db-id (t2/select-one-fn :id :model/Database :is_attached_dwh true)]- (when-let [dw-tables (t2/select :model/Table :db_id dw-db-id :active true)]+ (when-let [dw-tables (t2/select :model/Table :db_id dw-db-id :active true :is_upload false)]dw-tables))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -30,7 +30,9 @@;; See https://github.com/metabase/metabase/issues/41023(concat tables (attached-dwh-tables))(map #(update % :schema str) tables)- (filterv mi/can-read? tables)))+ (filter mi/can-read? tables)+ (sort-by :name tables) ;; Re-sort because we concat'ed data+ (vec tables)));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happendiff --git a/enterprise/backend/test/metabase_enterprise/upload_management/api_test.clj b/enterprise/backend/test/metabase_enterprise/upload_management/api_test.cljindex 204c1732673..9329618ee55 100644--- a/enterprise/backend/test/metabase_enterprise/upload_management/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/upload_management/api_test.clj@@ -36,6 +36,27 @@(map #(select-keys % [:name :display_name :id :entity_type :schema :usage_count]))set))))))))))+(deftest list-uploaded-tables-no-duplicates-test+ (testing "GET ee/upload-management/tables should not return duplicates for tables in attached DWH"+ (testing "Tables with is_upload=true in attached DWH should only appear once (not duplicated)"+ (mt/with-premium-features #{:upload-management :attached-dwh}+ (mt/with-temp [:model/Database {dwh-db-id :id} {:is_attached_dwh true}+ ;; Table in attached DWH with is_upload=true - should appear once, not twice+ :model/Table {upload-table-id :id} {:db_id dwh-db-id :is_upload true :active true :name "uploaded_table"}+ ;; Table in attached DWH without is_upload - should also appear+ :model/Table {non-upload-table-id :id} {:db_id dwh-db-id :is_upload false :active true :name "non_upload_table"}]+ (let [result (mt/user-http-request :crowberto :get 200 list-url)+ dwh-table-ids (->> result+ (filter #(= (:db_id %) dwh-db-id))+ (map :id))]+ (testing "Both tables should be in the result"+ (is (contains? (set dwh-table-ids) upload-table-id))+ (is (contains? (set dwh-table-ids) non-upload-table-id)))+ (testing "Upload table should appear exactly once (no duplicates)"+ (is (= 1 (count (filter #(= % upload-table-id) dwh-table-ids)))))+ (testing "Non-upload table should appear exactly once"+ (is (= 1 (count (filter #(= % non-upload-table-id) dwh-table-ids)))))))))))+(defn- delete-url [table-id](str "ee/upload-management/tables/" table-id))