Skip to content

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

fix: dirty state tracking of bulk set collections (#67020)

Edward Paget9a96a65abf8e
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
index 34951b62846..999311b3406 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
@@ -66,8 +66,14 @@
(doseq [collection sync-on
;; only publish event when this changed
:when (not (:is_remote_synced collection))]
- (events/publish-event! :event/collection-update {:object collection :user-id api/*current-user-id*}))
+ (events/publish-event! :event/collection-update
+ ;; collection is the model originally loaded set the correct sync state
+ {:object (assoc collection :is_remote_synced true)
+ :user-id api/*current-user-id*}))
(doseq [collection sync-off
;; only publish event when this changed
:when (:is_remote_synced collection)]
- (events/publish-event! :event/collection-update {:object collection :user-id api/*current-user-id*}))))
+ (events/publish-event! :event/collection-update
+ ;; collection is the model originally loaded set the correct sync state
+ {:object (assoc collection :is_remote_synced false)
+ :user-id api/*current-user-id*}))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
index 61dbd941b47..a8ec367c92b 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
@@ -145,6 +145,7 @@
(core/bulk-set-remote-sync {coll-id true})
(is (= 1 (count @published-events)))
(is (= :event/collection-update (ffirst @published-events)))
+ (is (true? (get-in (first @published-events) [1 :object :is_remote_synced])))
(is (= coll-id (get-in (first @published-events) [1 :object :id]))))))))
(deftest bulk-set-remote-sync-publishes-event-when-disabling-test
@@ -157,6 +158,7 @@
(core/bulk-set-remote-sync {coll-id false})
(is (= 1 (count @published-events)))
(is (= :event/collection-update (ffirst @published-events)))
+ (is (false? (get-in (first @published-events) [1 :object :is_remote_synced])))
(is (= coll-id (get-in (first @published-events) [1 :object :id]))))))))
(deftest bulk-set-remote-sync-no-event-when-already-enabled-test