Skip to content
Snippets Groups Projects
Unverified Commit 839f1f77 authored by Alexander Solovyov's avatar Alexander Solovyov Committed by GitHub
Browse files

xray should not filter again models with filters (#44547)

This not only does not make sense, but also fails for models with aggregations (and thus not having those fields for filtering available).
parent 2f6e5d7f
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
[clojure.walk :as walk]
[medley.core :as m]
[metabase.driver.util :as driver.u]
[metabase.models.card :as card]
[metabase.models.interface :as mi]
[metabase.query-processor.util :as qp.util]
[metabase.util :as u]
......@@ -78,13 +79,16 @@
{{:keys [database]} :root :keys [source query-filter]}]
(let [source-table (if (->> source (mi/instance-of? :model/Table))
(-> source u/the-id)
(->> source u/the-id (str "card__")))]
(->> source u/the-id (str "card__")))
model? (and (mi/instance-of? :model/Card source)
(card/model? source))]
(assoc ground-metric-with-dimensions
:dataset_query {:database database
:type :query
:query (cond-> (assoc metric-definition
:source-table source-table)
query-filter (assoc :filter query-filter))})))
(and (not model?)
query-filter) (assoc :filter query-filter))})))
(defn- instantiate-visualization
[[k v] dimensions metrics]
......
......@@ -655,6 +655,44 @@
:when name]
name)))))))))))
(deftest basic-root-model-test-4
(testing "Simple model with an aggregation and a filter should not leak filter to the upper cards"
(mt/dataset test-data
(mt/with-non-admin-groups-no-root-collection-perms
(let [source-query {:database (mt/id)
:query (mt/$ids
{:source-table $$products
:aggregation [[:count]],
:breakout [$products.id]
:filter [:time-interval $products.created_at -30 :day]})
:type :query}]
(mt/with-temp
[Collection {collection-id :id} {}
Card card {:table_id (mt/id :products)
:collection_id collection-id
:dataset_query source-query
:result_metadata (mt/with-test-user
:rasta
(result-metadata-for-query
source-query))
:type :model}]
(let [dashboard (mt/with-test-user :rasta (magic/automagic-analysis card nil))]
(ensure-single-table-sourced (mt/id :products) dashboard)
;; Count of records
;; Distributions:
;; - Summary statistics
;; - Count
;; - Distinct count
;; - Null values
(is (= 4 (->> dashboard :dashcards (filter :card) count)))
(ensure-dashboard-sourcing card dashboard)
;; This ensures we don't get :filter on queries derived from a model
(is (empty?
(for [{:keys [dataset_query]} (:dashcards dashboard)
:when (:filter dataset_query)]
dataset_query))))))))))
(deftest model-title-does-not-leak-abstraction-test
(testing "The title of a model or question card should not be X model or X question, but just X."
(mt/dataset test-data
......
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