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-4636: MB CLI doesn't have flag for expected branch, git-sync import fails with `expected_branch: missing required key, received: nil` (#82874)
Eric Normand361fc91d8025
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/api.cljindex dec09ed73b6..27998f46fc7 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj@@ -61,10 +61,12 @@;; the branch the client believes is currently active; rejected if it disagrees with the;; remote-sync-branch setting (a pull/switch from a stale tab). `branch` is the operational;; target (it differs from this on a branch switch); `expected_branch` is only the assertion.- [:expected_branch ms/NonBlankString]]]+ ;; Optional because headless clients (the `mb` CLI) hold no cached view that can go stale.+ [:expected_branch {:optional true} ms/NonBlankString]]](api/check-superuser)(api/check-400 (settings/remote-sync-enabled) "Remote sync is not configured.")- (check-branch-matches-setting! expected_branch)+ (when expected_branch+ (check-branch-matches-setting! expected_branch))(let [branch-name (or branch (settings/remote-sync-branch))user-id api/*current-user-id*{task-id :id}diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.cljindex 7dee4236f89..b8dec30d0b5 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj@@ -239,6 +239,19 @@(is (some (comp #{"Local Metric"} :name) (:dirty_objects resp))"the response lists the un-pushed local metric"))))))))+(deftest import-without-expected-branch-succeeds-test+ (testing "GHY-4636: `mb git-sync import` sends only `branch`; the import must run without `expected_branch`"+ (let [mock-main (test-helpers/create-mock-source)]+ (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 mock-main)]+ (let [{:keys [task_id] :as resp} (mt/user-http-request :crowberto :post 200 "ee/remote-sync/import"+ {:branch "main"})+ completed-task (wait-for-task-completion task_id)]+ (is (=? {:status "success" :task_id int?} resp))+ (is (remote-sync.task/successful? completed-task))))))))+(deftest import-rejects-expected-branch-mismatch-test(testing "POST /api/ee/remote-sync/import rejects when expected_branch disagrees with the configured setting"(let [mock-main (test-helpers/create-mock-source)]