Skip to content

Commit

Permalink
Merge pull request #7272 from metabase/fix-7253
Browse files Browse the repository at this point in the history
Fix #7253 🔧
  • Loading branch information
salsakran committed Apr 4, 2018
2 parents a554ad0 + 77c85a6 commit fa5cb8a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/metabase/query_processor/middleware/parameters/sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@
(s/optional-key :default) s/Any})

(def ^:private DimensionValue
{:type su/NonBlankString
:target s/Any
{:type su/NonBlankString
:target s/Any
;; not specified if the param has no value. TODO - make this stricter
(s/optional-key :value) s/Any
(s/optional-key :value) s/Any
;; The following are not used by the code in this namespace but may or may not be specified depending on what the
;; code that constructs the query params is doing. We can go ahead and ignore these when present.
(s/optional-key :slug) su/NonBlankString
(s/optional-key :name) su/NonBlankString
(s/optional-key :id) s/Any}) ; used internally by the frontend
(s/optional-key :slug) su/NonBlankString
(s/optional-key :name) su/NonBlankString
(s/optional-key :default) s/Any
(s/optional-key :id) s/Any}) ; used internally by the frontend

(def ^:private SingleValue
"Schema for a valid *single* value for a param. As of 0.28.0 params can either be single-value or multiple value."
Expand Down
34 changes: 34 additions & 0 deletions test/metabase/api/public_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,40 @@
:data
:rows)))))

;; make sure DimensionValue params also work if they have a default value, even if some is passed in for some reason
;; as part of the query (#7253)
;; If passed in as part of the query however make sure it doesn't override what's actually in the DB
(expect
[["Wow"]]
(tu/with-temporary-setting-values [enable-public-sharing true]
(tt/with-temp Card [card {:dataset_query {:database (data/id)
:type :native
:native {:query "SELECT {{msg}} AS message"
:template_tags {:msg {:id "181da7c5"
:name "msg"
:display_name "Message"
:type "text"
:required true
:default "Wow"}}}}}]
(with-temp-public-dashboard [dash {:parameters [{:name "Message"
:slug "msg"
:id "181da7c5"
:type "category"}]}]
(add-card-to-dashboard! card dash
:parameter_mappings [{:card_id (u/get-id card)
:target [:variable [:template-tag :msg]]
:parameter_id "181da7c5"}])
(-> ((test-users/user->client :crowberto)
:get (str (dashcard-url dash card)
"?parameters="
(json/generate-string
[{:type :category
:target [:variable [:template-tag :msg]]
:value nil
:default "Hello"}])))
:data
:rows)))))


;;; --------------------------- Check that parameter information comes back with Dashboard ---------------------------

Expand Down

0 comments on commit fa5cb8a

Please sign in to comment.