From: Mike Bayer Date: Thu, 7 Jan 2021 17:20:51 +0000 (-0500) Subject: Update connect args for pymysql 1.0.0; aiomysql fixes X-Git-Tag: rel_1_4_0b2~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=489301137a4d76e5a46d754ae9c91aad2b3d2c1f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Update connect args for pymysql 1.0.0; aiomysql fixes Fixed deprecation warnings that arose as a result of the release of PyMySQL 1.0, including deprecation warnings for the "db" and "passwd" parameters now replaced with "database" and "password". For the 1.4 version of this patch, we are also changing tox.ini to refer to a local branch of aiomysql that fixes pymysql compatibility issues. Fixes: #5821 Change-Id: I93876b52b2d96b52308f22aeb4f244ac5766a82f --- diff --git a/doc/build/changelog/unreleased_13/5821.rst b/doc/build/changelog/unreleased_13/5821.rst new file mode 100644 index 0000000000..a2c5d40824 --- /dev/null +++ b/doc/build/changelog/unreleased_13/5821.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, mysql + :tickets: 5821 + + Fixed deprecation warnings that arose as a result of the release of PyMySQL + 1.0, including deprecation warnings for the "db" and "passwd" parameters + now replaced with "database" and "password". + diff --git a/lib/sqlalchemy/dialects/mysql/aiomysql.py b/lib/sqlalchemy/dialects/mysql/aiomysql.py index 6381027e9f..f0665133f6 100644 --- a/lib/sqlalchemy/dialects/mysql/aiomysql.py +++ b/lib/sqlalchemy/dialects/mysql/aiomysql.py @@ -264,10 +264,9 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql): return pool.AsyncAdaptedQueuePool def create_connect_args(self, url): - args, kw = super(MySQLDialect_aiomysql, self).create_connect_args(url) - if "passwd" in kw: - kw["password"] = kw.pop("passwd") - return args, kw + return super(MySQLDialect_aiomysql, self).create_connect_args( + url, _translate_args=dict(username="user", database="db") + ) def is_disconnect(self, e, connection, cursor): if super(MySQLDialect_aiomysql, self).is_disconnect( diff --git a/lib/sqlalchemy/dialects/mysql/mysqldb.py b/lib/sqlalchemy/dialects/mysql/mysqldb.py index ab5a78aad7..0318b50772 100644 --- a/lib/sqlalchemy/dialects/mysql/mysqldb.py +++ b/lib/sqlalchemy/dialects/mysql/mysqldb.py @@ -177,10 +177,13 @@ class MySQLDialect_mysqldb(MySQLDialect): connection, additional_tests ) - def create_connect_args(self, url): - opts = url.translate_connect_args( - database="db", username="user", password="passwd" - ) + def create_connect_args(self, url, _translate_args=None): + if _translate_args is None: + _translate_args = dict( + database="db", username="user", password="passwd" + ) + + opts = url.translate_connect_args(**_translate_args) opts.update(url.query) util.coerce_kw_type(opts, "compress", bool) diff --git a/lib/sqlalchemy/dialects/mysql/pymysql.py b/lib/sqlalchemy/dialects/mysql/pymysql.py index ad61c9e299..0c321f854b 100644 --- a/lib/sqlalchemy/dialects/mysql/pymysql.py +++ b/lib/sqlalchemy/dialects/mysql/pymysql.py @@ -57,6 +57,13 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb): def dbapi(cls): return __import__("pymysql") + def create_connect_args(self, url, _translate_args=None): + if _translate_args is None: + _translate_args = dict(username="user") + return super(MySQLDialect_pymysql, self).create_connect_args( + url, _translate_args=_translate_args + ) + def is_disconnect(self, e, connection, cursor): if super(MySQLDialect_pymysql, self).is_disconnect( e, connection, cursor diff --git a/setup.cfg b/setup.cfg index e151769dac..f7915e43b2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,7 +65,9 @@ postgresql_asyncpg = greenlet;python_version>="3" postgresql_psycopg2binary = psycopg2-binary postgresql_psycopg2cffi = psycopg2cffi -pymysql = pymysql +pymysql = + pymysql;python_version>="3" + pymysql<1;python_version<"3" aiomysql = aiomysql [egg_info] diff --git a/tox.ini b/tox.ini index 8c0e0b7498..8f2fd9de0f 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ deps=pytest>=4.6.11 # this can be 6.x once we are on python 3 only postgresql: .[postgresql_pg8000]; python_version >= '3' mysql: .[mysql] mysql: .[pymysql] - mysql: .[aiomysql]; python_version >= '3' + mysql: git+https://github.com/sqlalchemy/aiomysql@sqlalchemy_tox; python_version >= '3' mysql: .[mariadb_connector]; python_version >= '3' # we should probably try to get mysql_connector back in the mix