--- /dev/null
+.. change::
+ :tags: bug, mysql
+ :tickets: 10492
+ :versions: 2.0.23
+
+ Repaired a new incompatibility in the MySQL "pre-ping" routine where the
+ ``False`` argument passed to ``connection.ping()``, which is intended to
+ disable an unwanted "automatic reconnect" feature, is being deprecated in
+ MySQL drivers and backends, and is producing warnings for some versions of
+ MySQL's native client drivers. It's removed for mysqlclient, whereas for
+ PyMySQL and drivers based on PyMySQL, the parameter will be deprecated and
+ removed at some point, so API introspection is used to future proof against
+ these various stages of removal.
return on_connect
def do_ping(self, dbapi_connection):
- dbapi_connection.ping(False)
+ dbapi_connection.ping()
return True
def do_executemany(self, cursor, statement, parameters, context=None):
def import_dbapi(cls):
return __import__("pymysql")
+ @langhelpers.memoized_property
+ def _send_false_to_ping(self):
+ """determine if pymysql has deprecated, changed the default of,
+ or removed the 'reconnect' argument of connection.ping().
+
+ See #10492 and
+ https://github.com/PyMySQL/mysqlclient/discussions/651#discussioncomment-7308971
+ for background.
+
+ """ # noqa: E501
+
+ try:
+ Connection = __import__("pymysql.connections").Connection
+ except (ImportError, AttributeError):
+ return True
+ else:
+ insp = langhelpers.get_callable_argspec(Connection.ping)
+ try:
+ reconnect_arg = insp.args[1]
+ except IndexError:
+ return False
+ else:
+ return reconnect_arg == "reconnect" and (
+ not insp.defaults or insp.defaults[0] is not False
+ )
+
+ def do_ping(self, dbapi_connection):
+ if self._send_false_to_ping:
+ dbapi_connection.ping(False)
+ else:
+ dbapi_connection.ping()
+
+ return True
+
def create_connect_args(self, url, _translate_args=None):
if _translate_args is None:
_translate_args = dict(username="user")