Skip to content
Snippets Groups Projects
Unverified Commit b0eb2489 authored by metamben's avatar metamben Committed by GitHub
Browse files

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

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.
parent e8e77d64
No related branches found
No related tags found
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.
Finish editing this message first!
Please register or to comment