]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
re-enable tests for asyncmy; fix Binary
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 20:21:17 +0000 (15:21 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 23:00:30 +0000 (18:00 -0500)
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)

doc/build/changelog/unreleased_14/7593.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/asyncmy.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py
tox.ini

diff --git a/doc/build/changelog/unreleased_14/7593.rst b/doc/build/changelog/unreleased_14/7593.rst
new file mode 100644 (file)
index 0000000..ebb3406
--- /dev/null
@@ -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.
index 16981fd98d95342f5b4434f6b91aad9ddefa1089..521918a5a178b7e0c8dfeaea5dfbc3ada95105da 100644 (file)
@@ -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)
 
index 2fdea5e48e74203cbd81adf66dac6c2f6569f697..b96350ed077abb48cf3f3b55a101ce34ab38cb7e 100644 (file)
@@ -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",
index bf83b83b48bc55eaae569c2d50833dcdbeeacd47..e587211ffac25e10a51b2cf356b1cefed38a9f0b 100644 (file)
@@ -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 0483ea759f2f6b53cbf8015f858d5ce22a685d08..505af98e80e46a5f82ed510455fb2f939cbd4b47 100644 (file)
--- 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}