Skip to content
Snippets Groups Projects
Unverified Commit bef93ce0 authored by Braden Shepherdson's avatar Braden Shepherdson Committed by GitHub
Browse files

[QP, debug] Fix preprocessing diffs in Portal (#47154)

The Portal diff view wants `[before after]` pairs of the original data,
not the three-part output of `clojure.data/diff`. This fixes the
`qp.debug/debug>` output from the preprocessing middleware to emit
correct diffs.

Also, since the diffs are not useful when the query is converted between
legacy and pMBQL, this also attaches the *converted* input query to the
output query's Clojure metadata, and this converted value is used as the
basis for the diff.
parent 730a2657
Branches
Tags
No related merge requests found
(ns metabase.query-processor.preprocess
(:require
[clojure.data :as data]
[metabase.legacy-mbql.schema :as mbql.s]
[metabase.lib.convert :as lib.convert]
[metabase.lib.query :as lib.query]
......@@ -61,14 +60,16 @@
(-> (fn [query]
(let [query (cond-> query
(:lib/type query) ->legacy)]
(middleware-fn query)))
(vary-meta (middleware-fn query)
assoc :converted-form query)))
(with-meta (meta middleware-fn))))
(defn- ensure-pmbql [middleware-fn]
(-> (fn [query]
(let [query (cond->> query
(not (:lib/type query)) (lib.query/query (qp.store/metadata-provider)))]
(middleware-fn query)))
(vary-meta (middleware-fn query)
assoc :converted-form query)))
(with-meta (meta middleware-fn))))
(def ^:private middleware
......@@ -141,7 +142,8 @@
middleware-fn)]
(list middleware-fn-name '=> <>
^{:portal.viewer/default :portal.viewer/diff}
(data/diff query <>)))))
[(or (-> <> meta :converted-form) query)
<>]))))
;; make sure the middleware returns a valid query... this should be dev-facing only so no need to i18n
(when-not (map? <>)
(throw (ex-info (format "Middleware did not return a valid query.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment