Skip to content

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

Improve event creation remote-sync (#69768)

Nathan Voxland13681a004a4c
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
index bb26f7e5aec..7ddd470e1de 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
@@ -702,6 +702,35 @@
:status "create"}
(first entries)))))))
+(deftest timeline-event-api-create-tracks-timeline-test
+ (testing "timeline-create event with a Timeline object creates a remote sync entry (fixed behavior)"
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}
+ :model/TimelineEvent timeline-event {:name "Test Event"
+ :timestamp (t/offset-date-time)
+ :timezone "UTC"
+ :time_matters false
+ :timeline_id (:id timeline)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (testing "publishing with a TimelineEvent (old buggy behavior) does NOT create a sync entry"
+ (events/publish-event! :event/timeline-create
+ {:object timeline-event :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 0 (count entries))
+ "TimelineEvent lacks collection_id, so no sync entry should be created")))
+ (testing "publishing with a Timeline (correct behavior) creates a sync entry"
+ (events/publish-event! :event/timeline-create
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries))
+ "Should create exactly one remote sync entry")
+ (is (=? {:model_type "Timeline"
+ :model_id (:id timeline)
+ :status "create"}
+ (first entries))
+ "Remote sync entry should track the Timeline, not the TimelineEvent"))))))
+
(deftest timeline-update-event-creates-entry-test
(testing "timeline-update event creates remote sync object entry with update status"
(mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
diff --git a/src/metabase/timeline/api/timeline_event.clj b/src/metabase/timeline/api/timeline_event.clj
index 6033fd17ed8..719c257f3cd 100644
--- a/src/metabase/timeline/api/timeline_event.clj
+++ b/src/metabase/timeline/api/timeline_event.clj
@@ -55,7 +55,7 @@
(boolean source) (assoc :source source)
(boolean question_id) (assoc :question_id question_id)))
(u/prog1 (first (t2/insert-returning-instances! :model/TimelineEvent tl-event))
- (events/publish-event! :event/timeline-create {:object <> :user-id api/*current-user-id*})))))
+ (events/publish-event! :event/timeline-create {:object (t2/select-one :model/Timeline :id (:timeline_id <>)) :user-id api/*current-user-id*})))))
;; 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 happen