Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
5f253885
Unverified
Commit
5f253885
authored
1 year ago
by
metamben
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Ignore undefined tag parameters sent by the FE (#34933)
Fixes #34729.
parent
90c52924
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/lib/js.cljs
+13
-3
13 additions, 3 deletions
src/metabase/lib/js.cljs
test/metabase/lib/js_test.cljs
+31
-6
31 additions, 6 deletions
test/metabase/lib/js_test.cljs
with
44 additions
and
9 deletions
src/metabase/lib/js.cljs
+
13
−
3
View file @
5f253885
...
...
@@ -9,6 +9,7 @@
[
filter
])
(
:require
[
clojure.walk
:as
walk
]
[
goog.object
:as
gobject
]
[
medley.core
:as
m
]
[
metabase.lib.convert
:as
lib.convert
]
[
metabase.lib.core
:as
lib.core
]
...
...
@@ -30,10 +31,19 @@
;;; this is mostly to ensure all the relevant namespaces with multimethods impls get loaded.
(
comment
lib.core/keep-me
)
(
defn-
remove-undefined-properties
[
obj
]
(
cond->
obj
(
object?
obj
)
(
gobject/filter
(
fn
[
e
_
_
]
(
not
(
undefined?
e
))))))
(
defn-
convert-js-template-tags
[
tags
]
(
update-vals
(
js->clj
tags
)
#
(
->
%
(
update-keys
keyword
)
(
update
:type
keyword
))))
(
->
tags
(
gobject/map
(
fn
[
e
_
_
]
(
remove-undefined-properties
e
)))
js->clj
(
update-vals
#
(
->
%
(
update-keys
keyword
)
(
update
:type
keyword
)))))
(
defn
^
:export
extract-template-tags
"Extract the template tags from a native query's text.
...
...
This diff is collapsed.
Click to expand it.
test/metabase/lib/js_test.cljs
+
31
−
6
View file @
5f253885
(
ns
metabase.lib.js-test
(
:require
[
clojure.test
:refer
[
deftest
is
testing
]]
[
goog.object
:as
gobject
]
[
metabase.lib.js
:as
lib.js
]
[
metabase.lib.test-metadata
:as
meta
]
[
metabase.lib.test-util
:as
lib.tu
]
...
...
@@ -87,24 +88,48 @@
(
is
(
=
[
"collection"
]
(
js->clj
extras
)))))
(
defn-
add-undefined-params
"This simulates the FE setting some parameters to js/undefined."
[
template-tags
param-name
]
(
doto
(
gobject/get
template-tags
param-name
)
(
gobject/add
"options"
js/undefined
)
(
gobject/add
"default"
js/undefined
))
template-tags
)
(
deftest
^
:parallel
template-tags-test
(
testing
"Snippets in template tags round trip correctly (#33546)"
(
let
[
db
meta/database
snippets
{
"snippet: my snippet"
snippet-name
"snippet: my snippet"
snippets
{
snippet-name
{
:type
:snippet
:name
"snippet: my snippet"
,
:id
"fd5e96f7-08f8-486b-9919-b2ab72857db4"
,
:display-name
"Snippet: My Snippet"
,
:snippet-name
"my snippet"
,
:name
"snippet: my snippet"
:id
"fd5e96f7-08f8-486b-9919-b2ab72857db4"
:display-name
"Snippet: My Snippet"
:snippet-name
"my snippet"
:snippet-id
1
}}
query
(
lib.js/with-template-tags
(
lib.js/native-query
(
:id
db
)
meta/metadata-provider
"select * from foo {{snippet: my snippet}}"
)
(
clj->js
snippets
))]
(
add-undefined-params
(
clj->js
snippets
)
snippet-name
)
)]
(
is
(
=
snippets
(
get-in
query
[
:stages
0
:template-tags
])))
(
is
(
test.js/=
(
clj->js
snippets
)
(
lib.js/template-tags
query
))))))
(
deftest
^
:parallel
extract-template-tags-test
(
testing
"Undefined parameters are ignored (#34729)"
(
let
[
tag-name
"foo"
tags
{
tag-name
{
:type
:text
:name
tag-name
:display-name
"Foo"
:id
(
str
(
random-uuid
))}}]
(
is
(
=
{
"bar"
{
"type"
"text"
"name"
"bar"
"display-name"
"Bar"
"id"
(
get-in
tags
[
tag-name
:id
])}}
(
->
(
lib.js/extract-template-tags
"SELECT * FROM table WHERE {{bar}}"
(
add-undefined-params
(
clj->js
tags
)
tag-name
))
js->clj
))))))
(
deftest
^
:parallel
is-column-metadata-test
(
is
(
true?
(
lib.js/is-column-metadata
(
meta/field-metadata
:venues
:id
))))
(
is
(
false?
(
lib.js/is-column-metadata
1
))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment