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
GHY-4642: Renaming a collection and exporting via Remote Sync doesn't update repo paths for content in renamed collection (#82865)
Eric Normand8ce3936116cd
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.cljindex f2455b949ce..17652dca4c4 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj@@ -993,6 +993,14 @@:model_id model_id:file_path (:new-path file-info)}]}+ ;; a collection's path is also its contents' directory, so moving the collection moves every+ ;; descendant's file too; only a full export rewrites them all+ (and (= "Collection" model_type)+ (= "update" status)+ (not (str/blank? file_path))+ (not= file_path (:new-path file-info)))+ :remote-sync/incremental-not-possible+;; rename: update whose stored path differs from new path. Write the;; new file and delete the old one.(and (= "update" status)diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.cljindex 01cd7bbf2d0..7dee4236f89 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj@@ -693,6 +693,32 @@(testing "Can export with force"(mt/user-http-request :crowberto :post 200 "ee/remote-sync/export" {:force true :branch "main"})))))))))+(deftest export-after-collection-rename-moves-contents-test+ (testing "GHY-4642: pushing after a synced collection is renamed moves its contents' files under the new collection path"+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Collection 2" :location "/"}+ :model/Card _ {:name "Question 2" :collection_id coll-id}]+ (let [source (test-helpers/versioned-source :current "v-remote" :trees {"v-remote" {}})+ repo-files #(set (source.p/list-files (source.p/snapshot source)))+ push! #(wait-for-task-completion+ (:task_id (mt/user-http-request :crowberto :post 200 "ee/remote-sync/export" {:branch "main"})))]+ (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git"+ remote-sync-token "test-token"+ remote-sync-branch "main"]+ (mt/with-dynamic-fn-redefs [source/source-from-settings (constantly source)+ settings/check-and-update-remote-settings! (constantly nil)+ impl/finish-remote-config! (constantly nil)]+ (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings" {:collections {coll-id true}})+ (is (remote-sync.task/successful? (push!)))+ (is (= #{"collections/main/collection_2.yaml"+ "collections/main/collection_2/question_2.yaml"}+ (repo-files)))+ (mt/user-http-request :crowberto :put 200 (str "collection/" coll-id) {:name "Marketing Reports"})+ (is (remote-sync.task/successful? (push!)))+ (is (= #{"collections/main/marketing_reports.yaml"+ "collections/main/marketing_reports/question_2.yaml"}+ (repo-files))))))))))+;;; ------------------------------------------------- Current Task Endpoint -------------------------------------------------(deftest current-task-requires-superuser-testdiff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.cljindex bf591cf16fe..89fcee8d677 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj@@ -149,6 +149,23 @@(is (= "apply-changes-version" (written-version task))"an in-place collection edit (no rename) is incremental")))))+(deftest collection-rename-falls-back-to-full-export-test+ (testing "GHY-4642: a collection's path is its contents' directory, so a rename re-exports everything and moves the contents"+ (with-exported-collection!+ (fn [{:keys [mock coll-id card-a card-b]}]+ (t2/update! :model/Collection coll-id {:name "Marketing Reports"})+ (set-status! "Collection" coll-id "update")+ (let [task (new-task!)+ result (impl/export! (source.p/snapshot mock) task "rename collection")]+ (is (= :success (:status result)))+ (is (= "write-files-version" (written-version task)) "collection rename is a full export")+ (is (= #{"collections/main/marketing_reports.yaml"+ "collections/main/marketing_reports/card_a.yaml"+ "collections/main/marketing_reports/card_b.yaml"}+ (set (keys (files mock)))))+ (is (= "collections/main/marketing_reports/card_a.yaml" (:file_path (rso "Card" card-a))))+ (is (= "collections/main/marketing_reports/card_b.yaml" (:file_path (rso "Card" card-b)))))))))+(deftest rename-uses-incremental-path-test(with-exported-collection!(fn [{:keys [mock card-a]}]