Skip to content
Snippets Groups Projects
Unverified Commit 2d150bf9 authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Check only :stages of the result of metric resolution in the QP (#49506) (#49561)


The query can contain all kinds of things, in particular the whole original query in the case of pivot questions, so
we should check only the part that actually gets resolved by the middleware.

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
parent c5a6b19b
Branches
Tags
No related merge requests found
......@@ -251,7 +251,7 @@
2. Metric source cards can reference themselves.
A query built from a `:source-card` of `:type :metric` can reference itself."
[query]
(if-not (find-first-metric query)
(if-not (find-first-metric (:stages query))
query
(do
(prometheus/inc! :metabase-query-processor/metrics-adjust)
......@@ -263,7 +263,7 @@
(update stage-or-join :stages #(adjust-metric-stages query path %)))))]
(u/prog1
(update query :stages #(adjust-metric-stages query nil %))
(when-let [metric (find-first-metric <>)]
(when-let [metric (find-first-metric (:stages <>))]
(throw (ex-info "Failed to replace metric" {:metric metric})))))
(catch Throwable e
(prometheus/inc! :metabase-query-processor/metrics-adjust-errors)
......
......@@ -59,8 +59,13 @@
(lib.tu/mock-metadata-provider
{:cards [metric]}))])))
(def adjust
(comp #'metrics/adjust #'fetch-source-query/resolve-source-cards))
(defn- adjust
[query]
(-> query
(assoc-in [:info :pivot/original-query] query)
(#'fetch-source-query/resolve-source-cards)
(#'metrics/adjust)
(dissoc :info)))
(defn- check-prometheus-metrics!
[& {expected-metrics-count :metabase-query-processor/metrics-adjust
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment