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
725a3a29
Unverified
Commit
725a3a29
authored
7 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Don't fail entire query if results metadata is invalid
parent
626901f3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/query_processor/middleware/results_metadata.clj
+21
-13
21 additions, 13 deletions
src/metabase/query_processor/middleware/results_metadata.clj
with
21 additions
and
13 deletions
src/metabase/query_processor/middleware/results_metadata.clj
+
21
−
13
View file @
725a3a29
...
...
@@ -4,6 +4,7 @@
as a checksum in the API response."
(
:require
[
buddy.core.hash
:as
hash
]
[
cheshire.core
:as
json
]
[
clojure.tools.logging
:as
log
]
[
metabase.models.humanization
:as
humanization
]
[
metabase.query-processor.interface
:as
i
]
[
metabase.util
:as
u
]
...
...
@@ -67,8 +68,8 @@
write bad queries; the field literals can only refer to columns in the original 'source' query at any rate, so you
wouldn't, for example, be able to give yourself access to columns in a different table.
However, if `MB_ENCRYPTION_SECRET_KEY` is set, we'll go ahead and use it to encypt the checksum so it becomes it
becomes
impossible to alter the metadata and produce a correct checksum at any rate."
However, if `MB_ENCRYPTION_SECRET_KEY` is set, we'll go ahead and use it to encypt the checksum so it becomes it
becomes
impossible to alter the metadata and produce a correct checksum at any rate."
[
metadata
]
(
when
metadata
(
encryption/maybe-encrypt
(
codec/base64-encode
(
hash/md5
(
json/generate-string
metadata
))))))
...
...
@@ -85,14 +86,21 @@
"Middleware that records metadata about the columns returned when running the query if it is associated with a Card."
[
qp
]
(
fn
[{{
:keys
[
card-id
nested?
]}
:info,
:as
query
}]
(
let
[
results
(
qp
query
)
metadata
(
results->column-metadata
results
)]
;; At the very least we can skip the Extra DB call to update this Card's metadata results
;; if its DB doesn't support nested queries in the first place
(
when
(
i/driver-supports?
:nested-queries
)
(
when
(
and
card-id
(
not
nested?
))
(
record-metadata!
card-id
metadata
)))
;; add the metadata and checksum to the response
(
assoc
results
:results_metadata
{
:checksum
(
metadata-checksum
metadata
)
:columns
metadata
}))))
(
let
[
results
(
qp
query
)]
(
try
(
let
[
metadata
(
results->column-metadata
results
)]
;; At the very least we can skip the Extra DB call to update this Card's metadata results
;; if its DB doesn't support nested queries in the first place
(
when
(
i/driver-supports?
:nested-queries
)
(
when
(
and
card-id
(
not
nested?
))
(
record-metadata!
card-id
metadata
)))
;; add the metadata and checksum to the response
(
assoc
results
:results_metadata
{
:checksum
(
metadata-checksum
metadata
)
:columns
metadata
}))
;; if for some reason we weren't able to record results metadata for this query then just proceed as normal
;; rather than failing the entire query
(
catch
Throwable
e
(
log/error
"Error recording results metadata for query:"
(
.getMessage
e
)
"\n"
(
u/pprint-to-str
(
u/filtered-stacktrace
e
)))
results
)))))
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