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
Admin notifications group by notification id not card id (#75928)
Ngoc Khuat0869369208c0
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 034e1335935..eb34421154f 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1460,6 +1460,7 @@:model/DashboardCard:model/DashboardTab:model/TaskHistory+ :model/TaskRun:model/User}}oauth-server@@ -2250,7 +2251,7 @@tasktracingutil}- :model-exports #{:model/TaskHistory}+ :model-exports #{:model/TaskHistory :model/TaskRun}:model-imports #{:model/Card :model/Dashboard :model/Database}}tenantsdiff --git a/resources/migrations/062/20260606_task_run_notification_id.yaml b/resources/migrations/062/20260606_task_run_notification_id.yamlnew file mode 100644index 00000000000..39afc960822--- /dev/null+++ b/resources/migrations/062/20260606_task_run_notification_id.yaml@@ -0,0 +1,95 @@+## Add task_run.notification_id so alert/subscription runs can be attributed to the exact+## notification that produced them (instead of only to the shared card/dashboard entity).+## Backfill is Postgres/MySQL only — H2 self-heals as runs age out of the 90-day display window.++databaseChangeLog:++ - changeSet:+ id: v62.2026-06-06T00:00:00+ author: qnkhuat+ comment: Add task_run.notification_id to attribute a run to the notification that produced it+ preConditions:+ - onFail: MARK_RAN+ - not:+ - columnExists:+ tableName: task_run+ columnName: notification_id+ # No FK: entity_id here is already FK-less (it's polymorphic), and task_run is a 90-day+ # operational log, not a relational parent.+ changes:+ - addColumn:+ tableName: task_run+ columns:+ - column:+ name: notification_id+ type: int+ remarks: ID of the notification that produced this run (null for non-notification runs, or runs predating this column)+ constraints:+ nullable: true+ rollback:+ - dropColumn:+ tableName: task_run+ columnName: notification_id++ - changeSet:+ id: v62.2026-06-06T00:00:01+ author: qnkhuat+ comment: Index task_run by (notification_id, started_at) for per-notification latest-run lookups+ preConditions:+ - onFail: MARK_RAN+ - not:+ - indexExists:+ indexName: idx_task_run_notification_id_started_at+ changes:+ - createIndex:+ tableName: task_run+ indexName: idx_task_run_notification_id_started_at+ columns:+ - column:+ name: notification_id+ - column:+ name: started_at+ descending: true+ rollback:+ - dropIndex:+ tableName: task_run+ indexName: idx_task_run_notification_id_started_at++ # Backfill the 90-day window (alerts + subscriptions) from each run's notification-send+ # task_history child. notification_id sits in task_details JSON, top-level or under `original-info`+ # on failure. task_details is always JSON-serialized by the model, so the cast is safe; a row+ # missing the key just yields NULL. The two SQL changes are dbms-gated; H2 matches neither and+ # ages out on its own.+ - changeSet:+ id: v62.2026-06-06T00:00:02+ author: qnkhuat+ comment: Backfill task_run.notification_id for the last 90 days (Postgres/MySQL; H2 ages out)+ changes:+ - sql:+ dbms: postgresql+ sql: >-+ UPDATE task_run tr+ SET notification_id = COALESCE(+ (th.task_details::jsonb) ->> 'notification_id',+ (th.task_details::jsonb) #>> '{original-info,notification_id}'+ )::int+ FROM task_history th+ WHERE th.run_id = tr.id+ AND th.task = 'notification-send'+ AND tr.run_type IN ('alert', 'subscription')+ AND tr.notification_id IS NULL+ AND tr.started_at > now() - interval '90 days';+ - sql:+ dbms: mysql,mariadb+ sql: >-+ UPDATE task_run tr+ JOIN task_history th ON th.run_id = tr.id+ SET tr.notification_id = CAST(COALESCE(+ JSON_UNQUOTE(JSON_EXTRACT(th.task_details, '$.notification_id')),+ JSON_UNQUOTE(JSON_EXTRACT(th.task_details, '$."original-info".notification_id'))+ ) AS UNSIGNED)+ WHERE th.task = 'notification-send'+ AND tr.run_type IN ('alert', 'subscription')+ AND tr.notification_id IS NULL+ AND tr.started_at > now() - interval 90 day;+ rollback: # nothing to do — column drop in the first changeSet covers itdiff --git a/src/metabase/notification/api/admin.clj b/src/metabase/notification/api/admin.cljindex 2eb38d35b92..7892f508521 100644--- a/src/metabase/notification/api/admin.clj+++ b/src/metabase/notification/api/admin.clj@@ -47,7 +47,6 @@;; ---------------------------------------------------------------------------(def ^:private run-type-alert "alert")-(def ^:private entity-type-card "card")(def ^:private task-notification-send "notification-send")(def ^:private task-channel-send "channel-send")(def ^:private terminal-statuses ["success" "failed" "abandoned"])@@ -179,49 +178,42 @@(defn- lookback-cutoff [](h2x/add-interval-honeysql-form (mdb/db-type) (mi/now) (- run-lookback-days) :day))-(defn- latest-run-per-card- "Honey.sql subquery: one row per card with the most recent terminal alert-type TaskRun- (status :success / :failed / :abandoned) within [[run-lookback-days]]. Excludes :started- in-flight runs — they shouldn't surface as a `last_check`. Uses- `ROW_NUMBER() OVER (PARTITION BY entity_id ORDER BY started_at DESC)`."+(defn- latest-run-per-notification+ "Honey.sql subquery: one row per notification with its most recent terminal alert-type TaskRun+ (status :success / :failed / :abandoned) within [[run-lookback-days]]. Excludes :started in-flight+ runs (they shouldn't surface as a `last_check`) and runs with no `notification_id` (unattributable,+ e.g. created before that column existed). Uses+ `ROW_NUMBER() OVER (PARTITION BY notification_id ORDER BY started_at DESC)`."[]- {:select [:id :entity_id :status :started_at :ended_at]- :from [[{:select [:id :entity_id :status :started_at :ended_at+ {:select [:id :notification_id :status :started_at :ended_at]+ :from [[{:select [:id :notification_id :status :started_at :ended_at[[:over [[:row_number]- {:partition-by [:entity_id]+ {:partition-by [:notification_id]:order-by [[:started_at :desc]]}]]:rn]]:from [:task_run]:where [:and[:= :run_type run-type-alert]- [:= :entity_type entity-type-card]+ [:is-not :notification_id nil][:in :status terminal-statuses][:> :started_at (lookback-cutoff)]]}:sub]]:where [:= :sub.rn 1]})-(defn- latest-send-tick-per-card- "Honey.sql subquery: one row per card summarising the LATEST tick that had channel-send- attempts within [[run-lookback-days]].-- Strategy (cross-dialect — no JSON, no SUM/aggregate type issues):- 1. Inner subquery `lr` — rank `task_run` rows that have at least one `channel-send`- child, by `started_at DESC` per card. Keep only rank=1 (the latest send-tick).- 2. Outer query — expose `entity_id` and `started_at`, plus `has_failure`: 1 if ANY- channel-send row under that run has status='failed', 0 otherwise. Uses a correlated- EXISTS rather than GROUP BY + SUM to stay H2/Postgres/MySQL compatible.+(defn- latest-send-tick-per-notification+ "Honey.sql subquery: one row per notification summarising the LATEST tick that had channel-send+ attempts within [[run-lookback-days]]. The inner subquery ranks each notification's runs that have+ a channel-send child by `started_at DESC` and keeps rank=1; the outer computes `has_failure` with+ a correlated EXISTS rather than GROUP BY + SUM, to stay H2/Postgres/MySQL compatible.Result columns:- - `:entity_id` — card ID (join key used by base-list-query)+ - `:notification_id` — join key used by base-list-query- `:id` — task_run.id of the latest send tick (for looking up channel-send error msg)- `:started_at` — the tick's started_at (for sort + `:last_send.at`)- - `:has_failure` — 1 if any channel-send in the tick failed, 0 otherwise-- Note: `:last_send` on the list endpoint is card-level (not per-notification). Per-notification- filtering is handled in `send-history-for-notification` on the detail page."+ - `:has_failure` — true if any channel-send in the tick failed"[](let [lookback (lookback-cutoff)]- {:select [:lr.entity_id+ {:select [:lr.notification_id[:lr.run_id :id][:lr.tick_started_at :started_at];; Boolean CASE, read back in Clojure — same pattern as@@ -237,17 +229,17 @@true:else false]:has_failure]]- :from [[{:select [:tr2.entity_id+ :from [[{:select [:tr2.notification_id[:tr2.id :run_id][:tr2.started_at :tick_started_at][[:over [[:row_number]- {:partition-by [:tr2.entity_id]+ {:partition-by [:tr2.notification_id]:order-by [[:tr2.started_at :desc]]}]]:rn]]:from [[:task_run :tr2]]:where [:and[:= :tr2.run_type run-type-alert]- [:= :tr2.entity_type entity-type-card]+ [:is-not :tr2.notification_id nil][:in :tr2.status terminal-statuses][:> :tr2.started_at lookback];; only keep runs that actually had channel-send rows@@ -362,10 +354,12 @@(sql.helpers/left-join [:report_card :c] [:= :c.id :nc.card_id])(sql.helpers/left-join [:core_user :cu] [:= :cu.id :notification.creator_id]))- ;; Window subquery joins — skipped on the detail path (see docstring).+ ;; Window subquery joins — skipped on the detail path (see docstring). Keyed by notification_id+ ;; so each notification gets exactly its own latest run, not the card's (which would bleed+ ;; across every notification sharing the card).(not skip-run-joins?)- (-> (sql.helpers/left-join [(latest-run-per-card) :lc] [:= :lc.entity_id :nc.card_id])- (sql.helpers/left-join [(latest-send-tick-per-card) :ls] [:= :ls.entity_id :nc.card_id])))+ (-> (sql.helpers/left-join [(latest-run-per-notification) :lc] [:= :lc.notification_id :notification.id])+ (sql.helpers/left-join [(latest-send-tick-per-notification) :ls] [:= :ls.notification_id :notification.id])))(list-where-clauses filters)))(defn- order-by-clauses@@ -461,7 +455,7 @@(into {} (map (juxt :run_id (comp :message :task_details)))))))(defn- has-failure?- "True when the `has_failure` value from `latest-send-tick-per-card` indicates at least one+ "True when the `has_failure` value from `latest-send-tick-per-notification` indicates at least onechannel failure. `bit->boolean` absorbs the MySQL/MariaDB bit-vs-boolean JDBC quirk so H2,Postgres, and MySQL all read uniformly."[v]@@ -474,7 +468,7 @@:last_check error uses the tiebreaker (prefer the outer notification-send message; fall back tothe latest by ended_at). :last_send error is restricted to channel-send rows — `last_send` isspecifically about the send tick, and the outer notification-send may have succeeded.- :last_send is nil when ls_started_at is nil (no send ever attempted for this card)."+ :last_send is nil when ls_started_at is nil (no send ever attempted for this notification)."[rows](let [failed-lc-ids (into #{} (keep (fn [{:keys [lc_id lc_status]}](when (#{"failed" "abandoned"} lc_status) lc_id)))@@ -535,13 +529,13 @@`offset` query params — handled by the offset-paging middleware), filtering, and sorting.`last_send_status` filter operates on the latest channel-send task_history row for the- notification's card (`successful` = latest channel-send succeeded; `failing` = latest- channel-send failed).+ notification (`successful` = latest channel-send succeeded; `failing` = latest channel-send+ failed).- `last_check_status` filter operates on the latest terminal TaskRun for the card — the whole-run- rollup (`successful` = the run succeeded; `failing` = it failed or was abandoned). This is a- superset of `last_send_status`: it also catches query failures and heartbeat-abandoned runs that- never reached the send step. The Failing tab uses `?last_check_status=failing`.+ `last_check_status` filter operates on the latest terminal TaskRun for the notification — the+ whole-run rollup (`successful` = the run succeeded; `failing` = it failed or was abandoned). This+ is a superset of `last_send_status`: it also catches query failures and heartbeat-abandoned runs+ that never reached the send step. The Failing tab uses `?last_check_status=failing`.`creatorless=true` selects notifications with no creator or a deactivated creator (the Ownerlesstab). `creatorless=false` selects the inverse.@@ -583,29 +577,6 @@;; Detail endpoint helpers;; ----------------------------------------------------------------------------(defn- task-history-rows-for-card- "Reducible source of `task-name` task_history rows for `card-id`, joined to task_run for tick- metadata, newest first. Bounded at `:fetch-limit` rows as a safety upper bound — callers should- combine with `(take …)` in the transducer so the JDBC cursor short-circuits once the- in-memory `notification_id` filter has yielded enough matches."- [card-id task-name & {:keys [fetch-limit extra-where] :or {fetch-limit 500}}]- (t2/reducible-select :model/TaskHistory- {:select [:th.run_id :th.task_details :th.status- [:tr.id :task_run_id]- [:tr.status :run_status]- [:tr.started_at :run_started_at]]- :from [[:task_history :th]]- :join [[:task_run :tr] [:= :tr.id :th.run_id]]- :where (cond-> [:and- [:= :tr.run_type run-type-alert]- [:= :tr.entity_type entity-type-card]- [:= :tr.entity_id card-id]- [:= :th.task task-name]- [:> :tr.started_at (lookback-cutoff)]]- extra-where (conj extra-where))- :order-by [[:tr.started_at :desc]]- :limit fetch-limit}))-(defn- task-details-key"Look up `k` in `task_details`, checking top level then `:original-info` (where`with-task-history` nests the caller's payload on failure)."@@ -613,34 +584,6 @@(or (get task_details k)(get-in task_details [:original-info k])))-(defn- matches-notification?- "Row predicate: true when `task_details.notification_id` matches `notification-id`."- [notification-id]- (fn [{:keys [task_details]}]- (= notification-id (task-details-key task_details :notification_id))))--(defn- check-history-for-notification- "Up to `:result-limit` most-recent terminal TaskRuns for `notification-id`, newest first, as- `::run-summary` maps."- [card-id notification-id & {:keys [fetch-limit result-limit] :or {fetch-limit 500 result-limit 10}}]- (let [matching (into []- ;; `realize` each matched row before exiting the reduction — the- ;; reducible-select rows are transient views over the JDBC cursor and- ;; become unreadable once `take` closes the reducible.- (comp (filter (matches-notification? notification-id))- (take result-limit)- (map t2.realize/realize))- (task-history-rows-for-card card-id task-notification-send- :fetch-limit fetch-limit- :extra-where [:in :tr.status terminal-statuses]))- failed-ids (into #{} (keep #(when (#{"failed" "abandoned"} (:run_status %)) (:task_run_id %)) matching))- errors (error-by-run-id nil failed-ids)]- (mapv (fn [{:keys [task_run_id run_status run_started_at]}]- (run->summary {:status (coerce-status run_status)- :at run_started_at- :error (get errors task_run_id)}))- matching)))-(defn- ->channel-entry"Build a single `::channel-entry` from a channel-send task_history row."[{:keys [status task_details]}]@@ -652,19 +595,36 @@:error (when (= run-status :failing)(:message task_details))}))+(defn- check-history-for-notification+ "Up to `:result-limit` most-recent terminal alert TaskRuns for `notification-id`, newest first, as+ `::run-summary` maps. Attributed directly via `task_run.notification_id`."+ [notification-id & {:keys [result-limit] :or {result-limit 10}}]+ (let [runs (t2/select [:model/TaskRun :id :status :started_at]+ {:where [:and+ [:= :run_type run-type-alert]+ [:= :notification_id notification-id]+ [:in :status terminal-statuses]+ [:> :started_at (lookback-cutoff)]]+ :order-by [[:started_at :desc] [:id :desc]]+ :limit result-limit})+ failed-ids (into #{} (keep (fn [{:keys [id status]}]+ (when (#{:failed :abandoned} status) id))+ runs))+ errors (error-by-run-id nil failed-ids)]+ (mapv (fn [{:keys [id status started_at]}]+ (run->summary {:status status :at started_at :error (get errors id)}))+ runs)))+(defn- send-history-for-notification"Up to `:result-limit` most-recent send ticks for `notification-id`, newest first, each a- `::tick-send-entry` rolling up all channels in that tick. Ticks with no channel-send rows- (e.g. goal-not-met) only appear in check_history."- [card-id notification-id & {:keys [fetch-limit result-limit] :or {fetch-limit 500 result-limit 10}}]- ;; Stream channel-send rows newest-first, filter to this notification, partition into ticks- ;; (rows of one tick are adjacent in started_at-desc order), take `result-limit` ticks, build- ;; the tick-send entries. The transducer short-circuits once `result-limit` partitions are seen.- ;; `realize` each matched row before `partition-by` holds it — reducible-select rows are- ;; transient views over the JDBC cursor that go invalid once `take` closes the reducible.+ `::tick-send-entry` rolling up all channels in that tick. Channel-send rows are attributed via+ their run's `task_run.notification_id`."+ [notification-id & {:keys [result-limit] :or {result-limit 10}}]+ ;; channel-send rows of one tick share a run_id and are adjacent in started_at-desc order, so+ ;; partition-by run_id segments them into ticks; take `result-limit` ticks. `realize` each row+ ;; before partition-by holds it — reducible-select rows go invalid once `take` closes the cursor.(into []- (comp (filter (matches-notification? notification-id))- (map t2.realize/realize)+ (comp (map t2.realize/realize)(partition-by :run_id)(take result-limit)(map (fn [tick-rows]@@ -673,26 +633,36 @@:status (if (some #(= :failing (:status %)) channel-entries) :failing :successful):error (some :error channel-entries):channels channel-entries}))))- (task-history-rows-for-card card-id task-channel-send :fetch-limit fetch-limit)))+ (t2/reducible-select :model/TaskHistory+ {:select [:th.run_id :th.task_details :th.status+ [:tr.started_at :run_started_at]]+ :from [[:task_history :th]]+ :join [[:task_run :tr] [:= :tr.id :th.run_id]]+ :where [:and+ [:= :tr.run_type run-type-alert]+ [:= :tr.notification_id notification-id]+ [:= :th.task task-channel-send]+ [:> :tr.started_at (lookback-cutoff)]]+ ;; tr.id tie-breaks runs sharing a started_at so partition-by run_id+ ;; keeps each run's rows adjacent.+ :order-by [[:tr.started_at :desc] [:tr.id :desc]]+ ;; safety cap; the (take result-limit) over partition-by run_id+ ;; normally closes the cursor first.+ :limit 500})))(defn- get-notification-detail"Fetch a single card-type notification with `:last_check`, `:last_send`, `:check_history`, and- `:send_history` (each per-notification, not card-level). Returns nil for a missing or non-card- notification."+ `:send_history`, each attributed to THIS notification via `task_run.notification_id`. Returns nil+ for a missing or non-card notification."[id](when-let [row (t2/select-one :model/Notification(-> (base-list-query {:skip-run-joins? true})(sql.helpers/where [:= :notification.id id])))]- ;; `base-list-query` with `:skip-run-joins?` doesn't project lc_*/ls_* columns, so we go- ;; straight from hydration to splice and derive last_check / last_send from the- ;; per-notification histories (which are also internally consistent and not subject to- ;; card-level bleed from other notifications sharing the same card).(let [decorated (-> (models.notification/hydrate-notification [row])firstsplice-creator-active)- card-id (get-in decorated [:payload :card_id])- check-history (if card-id (check-history-for-notification card-id id) [])- send-history (if card-id (send-history-for-notification card-id id) [])]+ check-history (check-history-for-notification id)+ send-history (send-history-for-notification id)](assoc decorated:last_check (first check-history):last_send (some-> (first send-history) (select-keys [:at :status :error]))diff --git a/src/metabase/notification/send.clj b/src/metabase/notification/send.cljindex a55bffb10c4..74bc3455ad7 100644--- a/src/metabase/notification/send.clj+++ b/src/metabase/notification/send.clj@@ -450,18 +450,20 @@- Dashboard notifications (subscriptions): run_type :subscription, entity_type :dashboard- Returns nil for other notification types or if entity_id would be nil.Handles both hydrated notifications (with :payload) and non-hydrated (with :payload_id)."- [{:keys [payload_type payload payload_id]}]+ [{:keys [id payload_type payload payload_id]}](case payload_type:notification/card (when-let [card-id (or (:card_id payload)(some->> payload_id(t2/select-one-fn :card_id :model/NotificationCard :id)))]- {:run_type :alert- :entity_type :card- :entity_id card-id})+ {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id id}):notification/dashboard (when-let [dashboard-id (:dashboard_id payload)]- {:run_type :subscription- :entity_type :dashboard- :entity_id dashboard-id})+ {:run_type :subscription+ :entity_type :dashboard+ :entity_id dashboard-id+ :notification_id id})nil))(mu/defn send-notification!diff --git a/src/metabase/task_history/models/task_run.clj b/src/metabase/task_history/models/task_run.cljindex 2e3112d68b7..db8eda58130 100644--- a/src/metabase/task_history/models/task_run.clj+++ b/src/metabase/task_history/models/task_run.clj@@ -81,23 +81,27 @@(mr/def ::TaskRunInfo[:map {:closed true}- [:run_type (into [:enum] run-types)]- [:entity_type (into [:enum] entity-types)]- [:entity_id ms/PositiveInt]- [:auto-complete {:optional true} [:maybe :boolean]]])+ [:run_type (into [:enum] run-types)]+ [:entity_type (into [:enum] entity-types)]+ [:entity_id ms/PositiveInt]+ ;; The notification this run is for, when applicable (alerts / subscriptions). Lets the run be+ ;; attributed to the exact notification rather than only to its shared card/dashboard entity.+ [:notification_id {:optional true} [:maybe ms/PositiveInt]]+ [:auto-complete {:optional true} [:maybe :boolean]]])(mu/defn create-task-run! :- ms/PositiveInt"Create a new task run record. Returns the run ID."- [{:keys [run_type entity_type entity_id]} :- ::TaskRunInfo]+ [{:keys [run_type entity_type entity_id notification_id]} :- ::TaskRunInfo](let [now (mi/now)](t2/insert-returning-pk! :model/TaskRun- {:run_type run_type- :entity_type entity_type- :entity_id entity_id- :status :started- :started_at now- :updated_at now- :process_uuid config/local-process-uuid})))+ {:run_type run_type+ :entity_type entity_type+ :entity_id entity_id+ :notification_id notification_id+ :status :started+ :started_at now+ :updated_at now+ :process_uuid config/local-process-uuid})))(mu/defn complete-task-run!"Mark a task run as complete, deriving status from child tasks.diff --git a/test/metabase/app_db/schema_migrations_test.clj b/test/metabase/app_db/schema_migrations_test.cljindex c71f4e25566..84665ce6886 100644--- a/test/metabase/app_db/schema_migrations_test.clj+++ b/test/metabase/app_db/schema_migrations_test.clj@@ -3133,3 +3133,59 @@(testing "user-settings with a real coercion is untouched"(is (= "type/Number"(t2/select-one-fn :effective_type :metabase_field_user_settings :field_id with-coercion-id))))))))++(deftest task-run-notification-id-backfill-test+ ;; Backfill is Postgres/MySQL only: H2 has no JSON-path extraction functions and isn't a production+ ;; app-db anyway. Skip the whole test there.+ (when (#{:postgres :mysql} (mdb/db-type))+ (testing "v62 backfills task_run.notification_id from the notification-send task_history child"+ (impl/test-migrations ["v62.2026-06-06T00:00:00"] [migrate!]+ (let [recent (t/offset-date-time)+ old (t/minus (t/offset-date-time) (t/days 100))+ new-run! (fn [started run-type status]+ (t2/insert-returning-pk! :task_run {:run_type run-type+ :entity_type "card"+ :entity_id 1+ :status status+ :started_at started}))+ new-th! (fn [run-id task status details]+ ;; insert via table name (not the model) so task_details is stored as the raw+ ;; JSON string the backfill reads, without the model's :json transform.+ (t2/insert! :task_history {:task task+ :status status+ :started_at recent+ :run_id run-id+ :task_details details}))+ ;; the three task_history shapes a real notification-send produces, plus the edge cases+ success (new-run! recent "alert" "success") ; normal: succeeded, notification_id top-level+ failed (new-run! recent "alert" "failed") ; failed: with-task-history nests under original-info+ abandoned (new-run! recent "alert" "abandoned") ; abandoned: died before writing any task_history+ too-old (new-run! old "alert" "success") ; outside the 90-day window+ chan-only (new-run! recent "alert" "success") ; only a channel-send child, no notification-send+ subscript (new-run! recent "subscription" "success") ; dashboard subscription, also attributed+ other (new-run! recent "sync" "success")] ; neither alert nor subscription+ (new-th! success "notification-send" "success" "{\"notification_id\":101}")+ (new-th! failed "notification-send" "failed" "{\"status\":\"failed\",\"message\":\"boom\",\"original-info\":{\"notification_id\":102}}")+ ;; `abandoned` intentionally has NO task_history (the run was killed before writing one)+ (new-th! too-old "notification-send" "success" "{\"notification_id\":104}")+ (new-th! chan-only "channel-send" "success" "{\"notification_id\":105,\"channel_type\":\"channel/email\"}")+ (new-th! subscript "notification-send" "success" "{\"notification_id\":107}")+ (new-th! other "notification-send" "success" "{\"notification_id\":106}")+ (migrate!)+ (let [nid #(t2/select-one-fn :notification_id :task_run :id %)]+ (testing "attributed from a notification-send child in the window"+ (testing "normal successful send, top-level notification_id"+ (is (= 101 (nid success))))+ (testing "failed send, notification_id nested under original-info"+ (is (= 102 (nid failed))))+ (testing "subscription run is attributed too"+ (is (= 107 (nid subscript)))))+ (testing "not attributed"+ (testing "abandoned run with no task_history stays null"+ (is (nil? (nid abandoned))))+ (testing "run older than the 90-day window"+ (is (nil? (nid too-old))))+ (testing "channel-send-only run (no notification-send)"+ (is (nil? (nid chan-only))))+ (testing "neither alert nor subscription"+ (is (nil? (nid other)))))))))))diff --git a/test/metabase/notification/api/admin_test.clj b/test/metabase/notification/api/admin_test.cljindex 02e5d846301..87279a46399 100644--- a/test/metabase/notification/api/admin_test.clj+++ b/test/metabase/notification/api/admin_test.clj@@ -390,12 +390,13 @@:model/Notification {n-unsent :id} {:payload_type :notification/card:payload_id nc-b:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-a- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-a+ :notification_id n-sent+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _th {:task "channel-send":run_id run-id:status :success@@ -420,12 +421,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _th {:task "channel-send":run_id run-id:status :failed@@ -447,12 +449,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun _run {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/instant)- :ended_at (t/instant)}]+ :model/TaskRun _run {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}](let [{:keys [data]} (mt/user-http-request :crowberto :get 200 "notification/admin")](is (=? {:last_check {:at some?:status "successful"@@ -466,12 +469,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _th {:task "notification-send":run_id run-id:status :failed@@ -491,12 +495,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)};; Outer notification-send succeeded; only the channel-send failed.:model/TaskHistory _ns-th {:task "notification-send":run_id run-id@@ -526,12 +531,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun _run {:run_type :alert- :entity_type :card- :entity_id card-id- :status :abandoned- :started_at (t/instant)- :ended_at (t/instant)}]+ :model/TaskRun _run {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :abandoned+ :started_at (t/instant)+ :ended_at (t/instant)}](let [{:keys [data]} (mt/user-http-request :crowberto :get 200 "notification/admin")](is (=? {:last_check {:status "failing"}}(find-row-by-id data nid)))@@ -546,16 +552,66 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun _run {:run_type :alert- :entity_type :card- :entity_id card-id- :status :started- :started_at (t/instant)}]+ :model/TaskRun _run {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :started+ :started_at (t/instant)}](let [{:keys [data]} (mt/user-http-request :crowberto :get 200 "notification/admin")](is (=? {:last_check nil:last_send nil}(find-row-by-id data nid)))))))+(deftest list-attributes-run-per-notification-no-bleed-test+ (testing "a run is shown only on the notification it was stamped for, never bled onto a sibling+ notification that shares the same card (the original bug)"+ (mt/with-temp [:model/Card {card-id :id} {:archived false}+ :model/NotificationCard {nc-ran :id} {:card_id card-id}+ :model/NotificationCard {nc-idle :id} {:card_id card-id}+ :model/Notification {ran :id} {:payload_type :notification/card+ :payload_id nc-ran+ :creator_id (mt/user->id :crowberto)}+ :model/Notification {idle :id} {:payload_type :notification/card+ :payload_id nc-idle+ :creator_id (mt/user->id :crowberto)}+ :model/TaskRun _run {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id ran+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}]+ (let [{:keys [data]} (mt/user-http-request :crowberto :get 200 "notification/admin")+ by-id (into {} (map (juxt :id identity) data))]+ (is (=? {:last_check {:status "successful"}} (by-id ran))+ "the run shows on the notification it was stamped for")+ (is (=? {:last_check nil} (by-id idle))+ "the sibling notification on the same card, with no run of its own, shows no last_check")))))++(deftest list-and-detail-agree-on-last-check-test+ (testing "the list and the detail endpoint report the SAME last_check for a notification, including+ an abandoned run — which is attributed via task_run.notification_id and has no task_history+ (this is the list-vs-detail mismatch from the bug report)"+ (mt/with-temp [:model/Card {card-id :id} {:archived false}+ :model/NotificationCard {nc :id} {:card_id card-id}+ :model/Notification {nid :id} {:payload_type :notification/card+ :payload_id nc+ :creator_id (mt/user->id :crowberto)}+ :model/TaskRun _run {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :abandoned+ :started_at (t/instant)+ :ended_at (t/instant)}]+ (let [list-row (-> (mt/user-http-request :crowberto :get 200 "notification/admin")+ :data (find-row-by-id nid))+ detail (mt/user-http-request :crowberto :get 200 (str "notification/admin/" nid))]+ (is (=? {:last_check {:status "failing"}} list-row))+ (is (= (:last_check list-row) (:last_check detail))+ "list and detail must agree on last_check, abandoned run included")))))+(deftest response-shape-includes-pagination-metadata-test(testing "GET / response shape echoes the {:data :total :limit :offset} pagination convention"(let [resp (mt/user-http-request :crowberto :get 200 "notification/admin")]@@ -586,18 +642,20 @@:model/Notification no-send-n {:payload_type :notification/card:payload_id nc-no-send:creator_id (mt/user->id :crowberto)}- :model/TaskRun {ok-run :id} {:run_type :alert- :entity_type :card- :entity_id success-card- :status :success- :started_at (t/instant)- :ended_at (t/instant)}- :model/TaskRun {fail-run :id} {:run_type :alert- :entity_type :card- :entity_id fail-card- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {ok-run :id} {:run_type :alert+ :entity_type :card+ :entity_id success-card+ :notification_id (:id success-n)+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}+ :model/TaskRun {fail-run :id} {:run_type :alert+ :entity_type :card+ :entity_id fail-card+ :notification_id (:id fail-n)+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)};; channel-send rows drive the filter:model/TaskHistory _ok-th {:task "channel-send":run_id ok-run@@ -643,26 +701,29 @@:model/Notification query-fail-n {:payload_type :notification/card:payload_id nc-query-fail:creator_id (mt/user->id :crowberto)}- :model/TaskRun {ok-run :id} {:run_type :alert- :entity_type :card- :entity_id ok-card- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {ok-run :id} {:run_type :alert+ :entity_type :card+ :entity_id ok-card+ :notification_id (:id ok-n)+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)};; heartbeat-killed run that never reached the channel-send step- :model/TaskRun _abandoned-run {:run_type :alert- :entity_type :card- :entity_id abandoned-card- :status :abandoned- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun _abandoned-run {:run_type :alert+ :entity_type :card+ :entity_id abandoned-card+ :notification_id (:id abandoned-n)+ :status :abandoned+ :started_at (t/instant)+ :ended_at (t/instant)};; query failure: notification-send failed, never produced a channel-send row- :model/TaskRun {qf-run :id} {:run_type :alert- :entity_type :card- :entity_id query-fail-card- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {qf-run :id} {:run_type :alert+ :entity_type :card+ :entity_id query-fail-card+ :notification_id (:id query-fail-n)+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _ok-th {:task "channel-send":run_id ok-run:status :success@@ -745,18 +806,20 @@:model/Notification {never-id :id} {:payload_type :notification/card:payload_id nc-never:creator_id (mt/user->id :crowberto)}- :model/TaskRun {old-run :id} {:run_type :alert- :entity_type :card- :entity_id card-old- :status :success- :started_at (t/minus (t/instant) (t/days 5))- :ended_at (t/minus (t/instant) (t/days 5))}- :model/TaskRun {new-run :id} {:run_type :alert- :entity_type :card- :entity_id card-new- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {old-run :id} {:run_type :alert+ :entity_type :card+ :entity_id card-old+ :notification_id old-id+ :status :success+ :started_at (t/minus (t/instant) (t/days 5))+ :ended_at (t/minus (t/instant) (t/days 5))}+ :model/TaskRun {new-run :id} {:run_type :alert+ :entity_type :card+ :entity_id card-new+ :notification_id new-id+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _old-th {:task "channel-send":run_id old-run:status :success@@ -819,12 +882,13 @@:model/Notification {unsent-id :id} {:payload_type :notification/card:payload_id nc-unsent:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-sent- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-sent+ :notification_id sent-id+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _th {:task "channel-send":run_id run-id:status :success@@ -1060,18 +1124,20 @@:model/Notification {never-id :id} {:payload_type :notification/card:payload_id nc-never:creator_id (mt/user->id :crowberto)}- :model/TaskRun _old-run {:run_type :alert- :entity_type :card- :entity_id card-old- :status :failed- :started_at (t/minus (t/instant) (t/days 5))- :ended_at (t/minus (t/instant) (t/days 5))}- :model/TaskRun _new-run {:run_type :alert- :entity_type :card- :entity_id card-new- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}]+ :model/TaskRun _old-run {:run_type :alert+ :entity_type :card+ :entity_id card-old+ :notification_id old-id+ :status :failed+ :started_at (t/minus (t/instant) (t/days 5))+ :ended_at (t/minus (t/instant) (t/days 5))}+ :model/TaskRun _new-run {:run_type :alert+ :entity_type :card+ :entity_id card-new+ :notification_id new-id+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)}](let [{:keys [data]} (mt/user-http-request :crowberto :get 200 "notification/admin":sort_column "last_check":sort_direction "desc")@@ -1114,18 +1180,20 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {r1 :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 2))- :ended_at (t/minus (t/instant) (t/hours 2))}- :model/TaskRun {r2 :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/minus (t/instant) (t/hours 1))- :ended_at (t/minus (t/instant) (t/hours 1))}+ :model/TaskRun {r1 :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/minus (t/instant) (t/hours 2))+ :ended_at (t/minus (t/instant) (t/hours 2))}+ :model/TaskRun {r2 :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/minus (t/instant) (t/hours 1))+ :ended_at (t/minus (t/instant) (t/hours 1))};; notification-send rows with notification_id — required for per-notification filter:model/TaskHistory _th1 {:task "notification-send":run_id r1@@ -1157,18 +1225,20 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-ok :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 2))- :ended_at (t/minus (t/instant) (t/hours 2))}- :model/TaskRun {run-fail :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/minus (t/instant) (t/hours 1))- :ended_at (t/minus (t/instant) (t/hours 1))}+ :model/TaskRun {run-ok :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/minus (t/instant) (t/hours 2))+ :ended_at (t/minus (t/instant) (t/hours 2))}+ :model/TaskRun {run-fail :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/minus (t/instant) (t/hours 1))+ :ended_at (t/minus (t/instant) (t/hours 1))}:model/TaskHistory _ok-th {:task "channel-send":run_id run-ok:status :success@@ -1216,12 +1286,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)};; notification-send: failure-wrapped (notification_id only under :original-info):model/TaskHistory _ns-th {:task "notification-send":run_id run-id@@ -1270,12 +1341,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)};; Outer notification-send: succeeded:model/TaskHistory _ns-th {:task "notification-send":run_id run-id@@ -1304,12 +1376,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :failed- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :failed+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _ns-th {:task "notification-send":run_id run-id:status :failed@@ -1334,12 +1407,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _email-th {:task "channel-send":run_id run-id:status :success@@ -1371,12 +1445,13 @@:model/Notification {nid :id} {:payload_type :notification/card:payload_id nc:creator_id (mt/user->id :crowberto)}- :model/TaskRun {run-id :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run-id :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _email-th {:task "channel-send":run_id run-id:status :success@@ -1424,10 +1499,11 @@;; create 12 runs, each with a matching notification-send row so the per-notification filter passes(doseq [i (range 12)](let [run-id (t2/insert-returning-pk! :model/TaskRun- {:run_type "alert"- :entity_type "card"- :entity_id card-id- :status "success"+ {:run_type "alert"+ :entity_type "card"+ :entity_id card-id+ :notification_id nid+ :status "success":started_at (t/minus (t/instant) (t/hours (inc i))):ended_at (t/minus (t/instant) (t/hours (inc i))):process_uuid "test"})]@@ -1483,12 +1559,13 @@:payload_id nc:creator_id (mt/user->id :crowberto)};; tick-A: fires for n1 only- :model/TaskRun {run-a :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 2))- :ended_at (t/minus (t/instant) (t/hours 2))}+ :model/TaskRun {run-a :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id n1+ :status :success+ :started_at (t/minus (t/instant) (t/hours 2))+ :ended_at (t/minus (t/instant) (t/hours 2))}:model/TaskHistory _ns-a {:task "notification-send":run_id run-a:status :success@@ -1503,12 +1580,13 @@:task_details {:channel_type "channel/email":notification_id n1}};; tick-B: fires for n2 only- :model/TaskRun {run-b :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 1))- :ended_at (t/minus (t/instant) (t/hours 1))}+ :model/TaskRun {run-b :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id n2+ :status :success+ :started_at (t/minus (t/instant) (t/hours 1))+ :ended_at (t/minus (t/instant) (t/hours 1))}:model/TaskHistory _ns-b {:task "notification-send":run_id run-b:status :success@@ -1549,12 +1627,13 @@:payload_id nc:creator_id (mt/user->id :crowberto)};; tick-1: goal not met — notification-send row exists but no channel-send- :model/TaskRun {run-skip :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 2))- :ended_at (t/minus (t/instant) (t/hours 2))}+ :model/TaskRun {run-skip :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/minus (t/instant) (t/hours 2))+ :ended_at (t/minus (t/instant) (t/hours 2))}:model/TaskHistory _ns-skip {:task "notification-send":run_id run-skip:status :success@@ -1563,12 +1642,13 @@:task_details {:notification_id nid:skip_reason "goal-not-met"}};; tick-2: goal met — has channel-send- :model/TaskRun {run-sent :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/minus (t/instant) (t/hours 1))- :ended_at (t/minus (t/instant) (t/hours 1))}+ :model/TaskRun {run-sent :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id nid+ :status :success+ :started_at (t/minus (t/instant) (t/hours 1))+ :ended_at (t/minus (t/instant) (t/hours 1))}:model/TaskHistory _ns-sent {:task "notification-send":run_id run-sent:status :success@@ -1603,12 +1683,13 @@:payload_id nc:creator_id (mt/user->id :crowberto)};; Only n2 has ever fired- :model/TaskRun {run2 :id} {:run_type :alert- :entity_type :card- :entity_id card-id- :status :success- :started_at (t/instant)- :ended_at (t/instant)}+ :model/TaskRun {run2 :id} {:run_type :alert+ :entity_type :card+ :entity_id card-id+ :notification_id n2+ :status :success+ :started_at (t/instant)+ :ended_at (t/instant)}:model/TaskHistory _ns2 {:task "notification-send":run_id run2:status :successdiff --git a/test/metabase/task_history/models/task_run_test.clj b/test/metabase/task_history/models/task_run_test.cljindex 4b986d4964b..2e6d125ce44 100644--- a/test/metabase/task_history/models/task_run_test.clj+++ b/test/metabase/task_history/models/task_run_test.clj@@ -329,19 +329,21 @@(deftest notification->task-run-info-test(testing "notification->task-run-info extracts correct info"- (testing "card notification (alert)"- (is (= {:run_type :alert :entity_type :card :entity_id 123}+ (testing "card notification (alert) is attributed to the notification id"+ (is (= {:run_type :alert :entity_type :card :entity_id 123 :notification_id 7}(notification.send/notification->task-run-info- {:payload_type :notification/card+ {:id 7+ :payload_type :notification/card:payload {:card_id 123}}))))(testing "card notification with nil card_id returns nil"(is (nil? (notification.send/notification->task-run-info{:payload_type :notification/card:payload {:card_id nil}}))))- (testing "dashboard notification (subscription)"- (is (= {:run_type :subscription :entity_type :dashboard :entity_id 456}+ (testing "dashboard notification (subscription) is attributed to the notification id"+ (is (= {:run_type :subscription :entity_type :dashboard :entity_id 456 :notification_id 9}(notification.send/notification->task-run-info- {:payload_type :notification/dashboard+ {:id 9+ :payload_type :notification/dashboard:payload {:dashboard_id 456}}))))(testing "dashboard notification with nil dashboard_id returns nil"(is (nil? (notification.send/notification->task-run-info