From: Mike Bayer Date: Mon, 25 Jul 2016 03:14:47 +0000 (-0400) Subject: - MySQL's JSON shared implementation completely w/ sqltypes.JSON; X-Git-Tag: rel_1_1_0b3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96c4208bf83607120d2f716070ed22ee10312dd0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - MySQL's JSON shared implementation completely w/ sqltypes.JSON; this must have been an oversight. Leave mysql.JSON in place still as we might need to add things to it. - CAST(json, String) still confusing MySQL drivers even mysqlclient. Since here we're checking for the raw form of the JSON and not a typical round trip, add a force for unicode Change-Id: I727f4526a01a0875037cf0dede45cd074da5205a --- diff --git a/lib/sqlalchemy/dialects/mysql/json.py b/lib/sqlalchemy/dialects/mysql/json.py index b2d5a78b5d..3840a7cd67 100644 --- a/lib/sqlalchemy/dialects/mysql/json.py +++ b/lib/sqlalchemy/dialects/mysql/json.py @@ -29,42 +29,7 @@ class JSON(sqltypes.JSON): """ - @util.memoized_property - def _str_impl(self): - return sqltypes.String(convert_unicode=True) - - def bind_processor(self, dialect): - string_process = self._str_impl.bind_processor(dialect) - - json_serializer = dialect._json_serializer or json.dumps - - def process(value): - if value is self.NULL: - value = None - elif isinstance(value, elements.Null) or ( - value is None and self.none_as_null - ): - return None - - serialized = json_serializer(value) - if string_process: - serialized = string_process(serialized) - return serialized - - return process - - def result_processor(self, dialect, coltype): - string_process = self._str_impl.result_processor(dialect, coltype) - json_deserializer = dialect._json_deserializer or json.loads - - def process(value): - if value is None: - return None - if string_process: - value = string_process(value) - return json_deserializer(value) - return process - + pass class JSONIndexType(sqltypes.JSON.JSONIndexType): def bind_processor(self, dialect): diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 6231e0fb9f..d74ef60da7 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -825,14 +825,14 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest): ) eq_( s.query( - cast(self.tables.data_table.c.data, String), + cast(self.tables.data_table.c.data, String(convert_unicode="force")), cast(self.tables.data_table.c.nulldata, String) ).filter(self.tables.data_table.c.name == 'd1').first(), ("null", None) ) eq_( s.query( - cast(self.tables.data_table.c.data, String), + cast(self.tables.data_table.c.data, String(convert_unicode="force")), cast(self.tables.data_table.c.nulldata, String) ).filter(self.tables.data_table.c.name == 'd2').first(), ("null", None)