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
95dab399
Unverified
Commit
95dab399
authored
1 year ago
by
Cal Herries
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle case when uploads table is not found (#31065)
parent
cbf5af96
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/api/card.clj
+4
-0
4 additions, 0 deletions
src/metabase/api/card.clj
test/metabase/api/card_test.clj
+34
-0
34 additions, 0 deletions
test/metabase/api/card_test.clj
with
38 additions
and
0 deletions
src/metabase/api/card.clj
+
4
−
0
View file @
95dab399
...
...
@@ -1153,6 +1153,10 @@ saved later when it is ready."
_
(
upload/load-from-csv
driver
db-id
schema+table-name
csv-file
)
_
(
sync/sync-database!
database
)
table-id
(
t2/select-one-fn
:id
Table
:db_id
db-id
:%lower.name
table-name
)]
(
when
(
nil?
table-id
)
(
driver/drop-table
driver
db-id
table-name
)
(
throw
(
ex-info
(
tru
"The CSV file was uploaded to {0} but the table could not be found on sync."
schema+table-name
)
{
:status-code
422
})))
(
create-card!
{
:collection_id
collection-id,
:dataset
true
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/card_test.clj
+
34
−
0
View file @
95dab399
...
...
@@ -16,6 +16,7 @@
[
metabase.driver
:as
driver
]
[
metabase.driver.sql-jdbc.connection
:as
sql-jdbc.conn
]
[
metabase.driver.sql-jdbc.execute
:as
sql-jdbc.execute
]
[
metabase.driver.util
:as
driver.u
]
[
metabase.http-client
:as
client
]
[
metabase.models
:refer
[
CardBookmark
...
...
@@ -2926,3 +2927,36 @@
java.lang.Exception
#
"^You do not have curate permissions for this Collection\.$"
(
upload-example-csv!
nil
)))))))))))
(
defn-
find-schema-filters-prop
[
driver
]
(
first
(
filter
(
fn
[
conn-prop
]
(
=
:schema-filters
(
keyword
(
:type
conn-prop
))))
(
driver/connection-properties
driver
))))
(
deftest
upload-csv!-schema-doesnt-sync-test
;; Just test with postgres because failure should be independent of the driver
(
mt/test-driver
:postgres
(
mt/with-empty-db
(
let
[
driver
(
driver.u/database->driver
(
mt/db
))
schema-filter-prop
(
find-schema-filters-prop
driver
)
filter-type-prop
(
keyword
(
str
(
:name
schema-filter-prop
)
"-type"
))
patterns-type-prop
(
keyword
(
str
(
:name
schema-filter-prop
)
"-patterns"
))]
(
t2/update!
Database
(
mt/id
)
{
:details
(
->
(
mt/db
)
:details
(
assoc
filter-type-prop
"exclusion"
patterns-type-prop
"public"
))})
(
mt/with-temporary-setting-values
[
uploads-enabled
true
uploads-database-id
(
mt/id
)
uploads-schema-name
"public"
]
(
testing
"Upload should fail if table can't be found after sync, for example because of schema filters"
(
try
(
upload-example-csv!
nil
)
(
catch
Exception
e
(
is
(
=
{
:status-code
422
}
(
.getData
e
)))
(
is
(
re-matches
#
"^The CSV file was uploaded to public\.example(.*) but the table could not be found on sync\.$"
(
.getMessage
e
))))))
(
testing
"\nThe table should be deleted"
(
is
(
false?
(
let
[
details
(
mt/dbdef->connection-details
driver/*driver*
:db
{
:database-name
(
:name
(
mt/db
))})]
(
->
(
jdbc/query
(
sql-jdbc.conn/connection-details->spec
driver/*driver*
details
)
[
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public')"
])
first
:exists
))))))))))
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