diff --git a/src/metabase/pulse/render/body.clj b/src/metabase/pulse/render/body.clj index f6a7f2dc0487924811bb8f5efde589184ad2334a..71385e4da411e4acdba8bc3a1520d23c1171b2a5 100644 --- a/src/metabase/pulse/render/body.clj +++ b/src/metabase/pulse/render/body.clj @@ -38,6 +38,8 @@ :padding :16px})} (trs "There was a problem with this question.")]})) +(def ^:private error-rendered-message (trs "An error occurred while displaying this card.")) + (def ^:private error-rendered-info "Default rendered-info map when there is an error displaying a card on the static viz side. Is a delay due to the call to `trs`." @@ -50,7 +52,7 @@ {:color style/color-error :font-weight 700 :padding :16px})} - (trs "An error occurred while displaying this card.")]})) + error-rendered-message]})) ;; NOTE: hiccup does not escape content by default so be sure to use "h" to escape any user-controlled content :-/ diff --git a/src/metabase/pulse/util.clj b/src/metabase/pulse/util.clj index dc86765593972252cfceeea509af1c3b227dabe0..596ecedd35be18538ec1dd4e56d0e67f36a7a884 100644 --- a/src/metabase/pulse/util.clj +++ b/src/metabase/pulse/util.clj @@ -92,7 +92,7 @@ (qp/userland-query query info) nil))))}) result (result-fn card-id) - series-results (map (comp result-fn :id) multi-cards)] + series-results (mapv (comp result-fn :id) multi-cards)] (when-not (and (get-in dashcard [:visualization_settings :card.hide_empty]) (is-card-empty? (assoc card :result (:result result)))) (update result :dashcard assoc :series-results series-results))) diff --git a/test/metabase/dashboard_subscription_test.clj b/test/metabase/dashboard_subscription_test.clj index a8c824ad2d7f97d02b24d2cf75f839ea8bc293d6..bd423178f0ff037b280d1a49a962b7b896879eb2 100644 --- a/test/metabase/dashboard_subscription_test.clj +++ b/test/metabase/dashboard_subscription_test.clj @@ -1003,7 +1003,6 @@ :channel/email first :message first :content (re-find #"<h1>dashboard description</h1>"))))))) - (deftest attachments-test (tests! {:card (pulse.test-util/checkins-query-card {})} @@ -1015,8 +1014,7 @@ (is (= (rasta-dashsub-message {:message [{"Aviary KPIs" true} pulse.test-util/png-attachment pulse.test-util/csv-attachment]}) - (-> (mt/summarize-multipart-single-email email - #"Aviary KPIs")))))}} + (mt/summarize-multipart-single-email email #"Aviary KPIs"))))}} "xlsx" {:pulse-card {:include_xls true} @@ -1026,8 +1024,7 @@ (is (= (rasta-dashsub-message {:message [{"Aviary KPIs" true} pulse.test-util/png-attachment pulse.test-util/xls-attachment]}) - (-> (mt/summarize-multipart-single-email email - #"Aviary KPIs")))))}} + (mt/summarize-multipart-single-email email #"Aviary KPIs"))))}} "no result should not include csv" {:card {:dataset_query (mt/mbql-query venues {:filter [:= $id -1]})} @@ -1040,5 +1037,44 @@ pulse.test-util/png-attachment ;; icon pulse.test-util/png-attachment]}) - (-> (mt/summarize-multipart-single-email email - #"Aviary KPIs")))))}})) + (mt/summarize-multipart-single-email email + #"Aviary KPIs"))))}})) + +(deftest multi-series-test + (mt/with-temp + [:model/Card {card-1 :id} {:name "Source card" + :display "line" + :dataset_query (mt/mbql-query orders + {:aggregation [[:sum $orders.total]] + :breakout [$orders.created_at]})} + :model/Card {card-2 :id} {:name "Serie card" + :display "line" + :dataset_query (mt/mbql-query orders + {:aggregation [[:sum $orders.subtotal]] + :breakout [$orders.created_at]})} + :model/Dashboard {dash-id :id} {:name "Aviary KPIs"} + :model/DashboardCard {dash-card-1 :id} {:dashboard_id dash-id + :card_id card-1} + :model/DashboardCardSeries _ {:dashboardcard_id dash-card-1 + :card_id card-2 + :position 0} + :model/Pulse {pulse-id :id} {:dashboard_id dash-id} + :model/PulseCard _ {:pulse_id pulse-id + :card_id card-1 + :position 0} + :model/PulseChannel {pc-id :id} {:pulse_id pulse-id + :channel_type "email"} + :model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id) + :pulse_channel_id pc-id}] + (testing "Able to send pulse with multi series card without rendering error #46892" + (let [error-msg (str @#'body/error-rendered-message)] + (is (= (rasta-dashsub-message {:message [{error-msg false} + ;; no result + pulse.test-util/png-attachment + ;; icon + pulse.test-util/png-attachment]}) + (-> (pulse.test-util/with-captured-channel-send-messages! + (metabase.pulse/send-pulse! (t2/select-one :model/Pulse pulse-id))) + :channel/email + first + (mt/summarize-multipart-single-email (re-pattern error-msg)))))))))