From 801b37bd2a983b441ea2d97b04865a188be10f2c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 20 Oct 2018 12:32:25 -0400 Subject: [PATCH] Enable decimal implicit bind for mysqlclient, is fixed as of post 1.3.13 Change-Id: Ic7a2055597d06038ab330f1114416e4538964a2b --- lib/sqlalchemy/dialects/mysql/mysqldb.py | 12 ++++++++++++ test/requirements.py | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/mysql/mysqldb.py b/lib/sqlalchemy/dialects/mysql/mysqldb.py index 7554d244cc..837dce5b77 100644 --- a/lib/sqlalchemy/dialects/mysql/mysqldb.py +++ b/lib/sqlalchemy/dialects/mysql/mysqldb.py @@ -87,6 +87,18 @@ class MySQLDialect_mysqldb(MySQLDialect): def __init__(self, server_side_cursors=False, **kwargs): super(MySQLDialect_mysqldb, self).__init__(**kwargs) self.server_side_cursors = server_side_cursors + self._mysql_dbapi_version = self._parse_dbapi_version( + self.dbapi.__version__) + + def _parse_dbapi_version(self, version): + m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', version) + if m: + return tuple( + int(x) + for x in m.group(1, 2, 3) + if x is not None) + else: + return (0, 0, 0) @util.langhelpers.memoized_property def supports_server_side_cursors(self): diff --git a/test/requirements.py b/test/requirements.py index 1cf40d8a4f..9afabc512d 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -945,7 +945,21 @@ class DefaultRequirements(SuiteRequirements): """ - return exclusions.fails_on("mysql+mysqldb", "driver specific") + # fixed for mysqlclient in + # https://github.com/PyMySQL/mysqlclient-python/commit/68b9662918577fc05be9610ef4824a00f2b051b0 + def check(config): + if against(config, "mysql+mysqldb"): + # can remove once post 1.3.13 is released + try: + from MySQLdb import converters + from decimal import Decimal + return Decimal not in converters.conversions + except: + return True + + return against(config, "mysql+mysqldb") and \ + config.db.dialect._mysql_dbapi_version <= (1, 3, 13) + return exclusions.fails_on(check, "fixed for mysqlclient post 1.3.13") @property def fetch_null_from_numeric(self): -- 2.47.2