This repository was archived by the owner on May 28, 2021. It is now read-only.
Workaround for sanitizing JSON coming from MySQL Shell #132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi
I am testing the operator ability to effectively recover a cluster in case of different types of failures, and I found a corner case that doesn't seem to be handled.
To replicate:
The first error I get in the log is:
It seems like MySQL shell is generating non-valid JSON since it escapes the single quotes in
Cluster has no quorum as visible from '127.0.0.1:3306'
, which is not an escapable character in JSON (https://www.json.org/, right table).The issue can be replicated also manually by running
mysqlsh --py
:Notice how printing the object correctly renders a valid json, however when using
print
like in the code (which is useful for other reasons, such as stripping\n
that show up during the pretty rendering), it gets mangled and the string ends up containing\'
:Which is the same error we get on the agent side. Notice that the standard dict Python implementation doesn't have this behavior, it seems to be specific to the types used inside MySQL shell:
Now, I think fully understanding the issue is beyond my paygrade, but digging into the MySQL Shell code I can find the definition of the
shell.Dict
custom type:https://github.com/mysql/mysql-shell/blob/8.0.11/mysqlshdk/scripting/python_map_wrapper.cc#L364
Inside this custom type, the defined
__str__
function,dict_printable
, seems to indeed always escape the single quote, leading to a non valid JSON.https://github.com/mysql/mysql-shell/blob/8.0.11/mysqlshdk/scripting/types.cc#L1234
I'm not sure what the right solution is (unfortunately
shell.Dict
doesn't seem serializable so we can't usejson.dumps
on it, which would definitely do the right encoding), but in the meantime I'm just submitting a dirty RFC patch that simply escapes such character.At the moment I'm hesitant to sign the Oracle CLA, I make this commit under the Apache License 2.0, feel free to use it as is, or also just report the changes in your own commit, I don't mind. Please let me know if it's going to be a problem.
Thanks