Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG24948205: Results from JSON_TYPE() are returned as bytearray
Result value from running a query with JSON_TYPE() is returned as a VAR_STRING value which is not converted and is returned as a bytearray. With this patch the returned value will be converted to a string type using the current charset, in case the conversion fail the value will still returned as a bytearray value. v2
- Loading branch information
Showing
2 changed files
with
5 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,7 +564,10 @@ def _STRING_to_python(self, value, dsc=None): # pylint: disable=C0103 | |
if dsc[7] & FieldFlag.SET: | ||
return self._SET_to_python(value, dsc) | ||
if dsc[7] & FieldFlag.BINARY: | ||
return value | ||
try: | ||
return value.decode(self.charset) | ||
except LookupError: | ||
return value | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
xcolwell
|
||
|
||
if self.charset == 'binary': | ||
return value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I found an edge case where this code change causes badness (in Python 2 btw). I have uuids stored in a BINARY(16) column. One of my uuids just so happens to have bytes that can be successfully decoded to utf8. Here's the culprit:
The code change above will happily decode my uuid, thereby breaking my application code which looks like:
The code that does
bytes(row['my_id'])
fails on the above ID which has been decoded to utf8.This behavior was introduced in 8.0.11 and does not exist in 8.0.6.
Any thoughts?