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
091c4a68
Unverified
Commit
091c4a68
authored
10 months ago
by
Cal Herries
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix null characters in JSON breaking CardRevisionAddType for postgres (#41584)
parent
470df0bf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/db/custom_migrations.clj
+7
-5
7 additions, 5 deletions
src/metabase/db/custom_migrations.clj
test/metabase/db/custom_migrations_test.clj
+26
-0
26 additions, 0 deletions
test/metabase/db/custom_migrations_test.clj
with
33 additions
and
5 deletions
src/metabase/db/custom_migrations.clj
+
7
−
5
View file @
091c4a68
...
...
@@ -1000,14 +1000,16 @@
(
define-reversible-migration
CardRevisionAddType
(
case
(
mdb.connection/db-type
)
:postgres
;; postgres doesn't allow `\u0000` in text when converting to jsonb, so we need to remove them before we can
;; parse the json. We use negative look behind to avoid matching `\\u0000` (metabase#40835)
(
t2/query
[
"UPDATE revision
SET object = jsonb_set(
object
::jsonb, '{type}',
SET object =
replace(
jsonb_set(
(regexp_replace(object, '(?<!\\\\)\\\\u0000', '286b707c-e895-4cd3-acfc-569147f54371', 'g'))
::jsonb, '{type}',
to_jsonb(CASE
WHEN (
object
::jsonb->>'dataset')::boolean THEN 'model'
WHEN (
(regexp_replace(object, '(?<!\\\\)\\\\u0000', '286b707c-e895-4cd3-acfc-569147f54371', 'g'))
::jsonb->>'dataset')::boolean THEN 'model'
ELSE 'question'
END)::jsonb, true)
WHERE model = 'Card' AND (
object
::jsonb->>'dataset') IS NOT NULL;"
])
END)::jsonb, true)
::text, '286b707c-e895-4cd3-acfc-569147f54371', '\\u0000')
WHERE model = 'Card' AND (
(regexp_replace(object, '(?<!\\\\)\\\\u0000', '286b707c-e895-4cd3-acfc-569147f54371', 'g'))
::jsonb->>'dataset') IS NOT NULL;"
])
:mysql
(
t2/query
[
"UPDATE revision
...
...
This diff is collapsed.
Click to expand it.
test/metabase/db/custom_migrations_test.clj
+
26
−
0
View file @
091c4a68
...
...
@@ -1600,6 +1600,32 @@
(
is
(
not
(
contains?
card-revision-object
"type"
)))
(
is
(
not
(
contains?
model-revision-object
"type"
))))))))
(
deftest
card-revision-add-type-null-character-test
(
testing
"CardRevisionAddType migration works even if there's a null character in revision.object (metabase#40835)"
)
(
impl/test-migrations
"v49.2024-01-22T11:52:00"
[
migrate!
]
(
let
[
user-id
(
:id
(
new-instance-with-default
:core_user
))
db-id
(
:id
(
new-instance-with-default
:metabase_database
))
card
(
new-instance-with-default
:report_card
{
:dataset
false
:creator_id
user-id
:database_id
db-id
})
viz-settings
"{\"table.pivot_column\":\"\u0000..\\u0000\"}"
; note the escaped and unescaped null characters
card-revision-id
(
:id
(
new-instance-with-default
:revision
{
:object
(
json/generate-string
(
assoc
(
dissoc
card
:type
)
:visualization_settings
viz-settings
))
:model
"Card"
:model_id
(
:id
card
)
:user_id
user-id
}))]
(
testing
"sanity check revision object"
(
let
[
card-revision-object
(
t2/select-one-fn
(
comp
json/parse-string
:object
)
:revision
card-revision-id
)]
(
testing
"doesn't have type"
(
is
(
not
(
contains?
card-revision-object
"type"
))))))
(
testing
"after migration card revisions should have type"
(
migrate!
)
(
let
[
card-revision-object
(
t2/select-one-fn
(
comp
json/parse-string
:object
)
:revision
card-revision-id
)]
(
is
(
=
"question"
(
get
card-revision-object
"type"
)))
(
testing
"original visualization_settings should be preserved"
(
is
(
=
viz-settings
(
get
card-revision-object
"visualization_settings"
)))))))))
(
deftest
delete-scan-field-values-trigger-test
(
testing
"We should delete the triggers for DBs that are configured not to scan their field values\n"
(
impl/test-migrations
"v49.2024-04-09T10:00:03"
[
migrate!
]
...
...
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