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
508b9931
Unverified
Commit
508b9931
authored
1 year ago
by
Cam Saul
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix NPE in schema pattern matching fns in sync (#38161)
* Fix NPE in schema pattern matching fns in sync * Require PG
parent
bdfaf72f
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/driver/sync.clj
+17
-11
17 additions, 11 deletions
src/metabase/driver/sync.clj
test/metabase/driver/sync_test.clj
+25
-9
25 additions, 9 deletions
test/metabase/driver/sync_test.clj
with
42 additions
and
20 deletions
src/metabase/driver/sync.clj
+
17
−
11
View file @
508b9931
...
...
@@ -40,11 +40,16 @@
:else
(
let
[
inclusion?
exclusion-blank?
pattern
(
schema-pattern->re-pattern
(
if
inclusion?
inclusion-patterns
exclusion-patterns
))]
(
fn
[
s
]
(
let
[
m
(
.matcher
pattern
s
)
matches?
(
.matches
m
)]
(
if
inclusion?
matches?
(
not
matches?
))))))))
pattern
(
schema-pattern->re-pattern
(
if
inclusion?
inclusion-patterns
exclusion-patterns
))
match-fn
(
fn
match-fn
[
^
String
s
]
(
when
s
(
let
[
m
(
.matcher
pattern
s
)]
(
.matches
m
))))]
;; for inclusion patterns, never match a `nil` schema; for exclusion patterns, always consider a `nil` schema to
;; be ok
(
if
inclusion?
match-fn
(
complement
match-fn
))))))
(
def
^
:private
schema-patterns->filter-fn
(
memoize
schema-patterns->filter-fn*
))
...
...
@@ -56,12 +61,13 @@
(
let
[{
prop-name
:name
}
(
driver.u/find-schema-filters-prop
(
driver.u/database->driver
database
))]
(
db-details->schema-filter-patterns
prop-name
database
)))
([
prop-nm
{
db-details
:details
:as
_database
}]
(
let
[
schema-filter-type
(
get
db-details
(
keyword
(
str
prop-nm
"-type"
)))
schema-filter-patterns
(
get
db-details
(
keyword
(
str
prop-nm
"-patterns"
)))]
(
case
schema-filter-type
"exclusion"
[
nil
schema-filter-patterns
]
"inclusion"
[
schema-filter-patterns
nil
]
[
nil
nil
]))))
(
when
prop-nm
(
let
[
schema-filter-type
(
get
db-details
(
keyword
(
str
prop-nm
"-type"
)))
schema-filter-patterns
(
get
db-details
(
keyword
(
str
prop-nm
"-patterns"
)))]
(
case
schema-filter-type
"exclusion"
[
nil
schema-filter-patterns
]
"inclusion"
[
schema-filter-patterns
nil
]
[
nil
nil
])))))
(
defn
include-schema?
"Returns true if the given `schema-name` should be included/synced, considering the given `inclusion-patterns` and
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/sync_test.clj
+
25
−
9
View file @
508b9931
(
ns
metabase.driver.sync-test
(
:require
[
clojure.test
:as
t
]
[
clojure.test
:refer
:all
]
[
metabase.driver.postgres
]
[
metabase.driver.sync
:as
driver.s
])
(
:import
(
clojure.lang
ExceptionInfo
)))
(
t/deftest
^
:parallel
schema-filter-test
(
comment
metabase.driver.postgres/keep-me
)
; this is used by [[schema-filter-NPE-test]] below
(
deftest
^
:parallel
schema-filter-test
(
doseq
[[
test-kind
expect-match?
schema-name
inclusion-filters
exclusion-filters
]
[[
"nil filters"
true
"foo"
nil
nil
]
[
"blank filters"
true
"foo"
""
""
]
...
...
@@ -20,10 +23,23 @@
[
"exclusion filter with commas and wildcards (include)"
true
"foo"
""
"ba*,fob"
]
[
"exclusion filter with commas and wildcards (exclude)"
false
"foo"
""
"bar,baz,fo*"
]
[
"multiple inclusion with whitespace trimming"
true
"bar"
" foo , bar \n , \nbaz "
""
]]]
(
t/testing
(
str
"include-schema? works as expected for "
test-kind
)
(
t/is
(
=
expect-match?
(
driver.s/include-schema?
inclusion-filters
exclusion-filters
schema-name
))))
(
t/testing
"include-schema? throws an exception if both patterns are specified"
(
t/is
(
thrown-with-msg?
ExceptionInfo
#
"Inclusion and exclusion patterns cannot both be specified"
(
driver.s/include-schema?
"foo"
"bar"
"whatever"
))))))
(
testing
(
str
"include-schema? works as expected for "
test-kind
)
(
is
(
=
expect-match?
(
driver.s/include-schema?
inclusion-filters
exclusion-filters
schema-name
))))
(
testing
"include-schema? throws an exception if both patterns are specified"
(
is
(
thrown-with-msg?
ExceptionInfo
#
"Inclusion and exclusion patterns cannot both be specified"
(
driver.s/include-schema?
"foo"
"bar"
"whatever"
))))))
(
deftest
^
:parallel
schema-filter-NPE-test
(
testing
"Schema filter function should not NPE if you pass in a `nil` schema (#38156)"
(
testing
"inclusion -- don't include nil schemas"
(
let
[
db
{
:details
{
:schema-filters-type
"inclusion"
:schema-filters-patterns
"x"
}
:engine
:postgres
}]
(
is
(
not
(
driver.s/include-schema?
db
nil
)))))
(
testing
"exclusion -- don't exclude nil schemas"
(
let
[
db
{
:details
{
:schema-filters-type
"exclusion"
:schema-filters-patterns
"x"
}
:engine
:postgres
}]
(
is
(
driver.s/include-schema?
db
nil
))))))
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