From: Mike Bayer Date: Thu, 20 Jan 2022 20:21:17 +0000 (-0500) Subject: re-enable tests for asyncmy; fix Binary X-Git-Tag: rel_1_4_31~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3c1271953287a94a52075cd9ad6032c43d4bfa5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git re-enable tests for asyncmy; fix Binary Fixed regression in asyncmy dialect caused by :ticket:`7567` where removal of the PyMySQL dependency broke binary columns, due to the asyncmy dialect not being properly included within CI tests. Fixes: #7593 Change-Id: Iefc1061c24c75fcb9ca1a02d0b5e5f43970ade17 (cherry picked from commit da128e11ff5fcaafbf80704dc0aa8da0a901fb3e) --- diff --git a/doc/build/changelog/unreleased_14/7593.rst b/doc/build/changelog/unreleased_14/7593.rst new file mode 100644 index 0000000000..ebb3406ed7 --- /dev/null +++ b/doc/build/changelog/unreleased_14/7593.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, mysql, regression + :tickets: 7593 + + Fixed regression in asyncmy dialect caused by :ticket:`7567` where removal + of the PyMySQL dependency broke binary columns, due to the asyncmy dialect + not being properly included within CI tests. diff --git a/lib/sqlalchemy/dialects/mysql/asyncmy.py b/lib/sqlalchemy/dialects/mysql/asyncmy.py index 16981fd98d..521918a5a1 100644 --- a/lib/sqlalchemy/dialects/mysql/asyncmy.py +++ b/lib/sqlalchemy/dialects/mysql/asyncmy.py @@ -228,6 +228,11 @@ class AsyncAdaptFallback_asyncmy_connection(AsyncAdapt_asyncmy_connection): await_ = staticmethod(await_fallback) +def _Binary(x): + """Return x as a binary type.""" + return bytes(x) + + class AsyncAdapt_asyncmy_dbapi: def __init__(self, asyncmy): self.asyncmy = asyncmy @@ -250,6 +255,13 @@ class AsyncAdapt_asyncmy_dbapi: ): setattr(self, name, getattr(self.asyncmy.errors, name)) + STRING = util.symbol("STRING") + NUMBER = util.symbol("NUMBER") + BINARY = util.symbol("BINARY") + DATETIME = util.symbol("DATETIME") + TIMESTAMP = util.symbol("TIMESTAMP") + Binary = staticmethod(_Binary) + def connect(self, *arg, **kw): async_fallback = kw.pop("async_fallback", False) diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 2fdea5e48e..b96350ed07 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -41,6 +41,8 @@ from ... import UnicodeText from ... import util from ...orm import declarative_base from ...orm import Session +from ...sql.sqltypes import LargeBinary +from ...sql.sqltypes import PickleType from ...util import compat from ...util import u @@ -196,6 +198,42 @@ class UnicodeTextTest(_UnicodeFixture, fixtures.TablesTest): self._test_null_strings(connection) +class BinaryTest(_LiteralRoundTripFixture, fixtures.TablesTest): + __requires__ = ("binary_literals",) + __backend__ = True + + @classmethod + def define_tables(cls, metadata): + Table( + "binary_table", + metadata, + Column( + "id", Integer, primary_key=True, test_needs_autoincrement=True + ), + Column("binary_data", LargeBinary), + Column("pickle_data", PickleType), + ) + + def test_binary_roundtrip(self, connection): + binary_table = self.tables.binary_table + + connection.execute( + binary_table.insert(), {"id": 1, "binary_data": b"this is binary"} + ) + row = connection.execute(select(binary_table.c.binary_data)).first() + eq_(row, (b"this is binary",)) + + def test_pickle_roundtrip(self, connection): + binary_table = self.tables.binary_table + + connection.execute( + binary_table.insert(), + {"id": 1, "pickle_data": {"foo": [1, 2, 3], "bar": "bat"}}, + ) + row = connection.execute(select(binary_table.c.pickle_data)).first() + eq_(row, ({"foo": [1, 2, 3], "bar": "bat"},)) + + class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): __requires__ = ("text_type",) __backend__ = True @@ -1445,6 +1483,7 @@ class JSONLegacyStringCastIndexTest( __all__ = ( + "BinaryTest", "UnicodeVarcharTest", "UnicodeTextTest", "JSONTest", diff --git a/test/requirements.py b/test/requirements.py index bf83b83b48..e587211ffa 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -1136,7 +1136,16 @@ class DefaultRequirements(SuiteRequirements): # pg8000 works in main / 2.0, support in 1.4 is not fully # present. return exclusions.skip_if("postgresql+pg8000") + exclusions.fails_on( - ["mysql", "mariadb"] + # mariadbconnector works. pyodbc we dont know, not supported in + # testing. + [ + "+mysqldb", + "+pymysql", + "+asyncmy", + "+mysqlconnector", + "+cymysql", + "+aiomysql", + ] ) @property diff --git a/tox.ini b/tox.ini index 0483ea759f..505af98e80 100644 --- a/tox.ini +++ b/tox.ini @@ -102,7 +102,7 @@ setenv= py2{,7}-mysql: MYSQL={env:TOX_MYSQL_PY2K:{env:TOX_MYSQL:--db mysql}} mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql} - py3-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver mariadbconnector --dbdriver asyncmy} + py3{,7,8,9,10,11}-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver mariadbconnector --dbdriver asyncmy} mssql: MSSQL={env:TOX_MSSQL:--db mssql}