Mysql Dialect Not Parsing 'connect_timeout' query string param Option

Issue #3787 resolved
andrew_page@harvard.edu created an issue
from sqlalchemy import create_engine

def main():
  uri = "mysql+mysqlconnector://uname:password@mysqlserver/realdb2?connect_timeout=5" # correct credentials to test
  e = create_engine(uri) 

  ##
  ## will produce a 
  ##  (mysql.connector.errors.OperationalError) an integer is required (got type str) 
  ## from the 
  ## site-packages/mysql/connector/network.py:471   mysql-connector 2.1.3
  ##
  ## while attempting to execute  self.sock.settimeout(self._connection_timeout)
  ## where self._connection_timeout is set to '5' (the str '5' not the integer 5)
  ## tracing back usages and parsing of the supplied uri
  ##
  ## MySQLDialect_mysqlconnector::create_connect_args  in site-packages/sqlalchemy/dialects/mysql/mysqlconnector.py:115
  ##
  ## and the lines: 
  ##      util.coerce_kw_type(opts, 'buffered', bool)
  ##      util.coerce_kw_type(opts, 'raise_on_warnings', bool)
  ##
  ## Where it is parsing SOME of the options for mysql but not all of them and leaving
  ## connect_timeout as a string
  ##
  e.execute("select sleep(10);") # error will occur here
  print("done")

if __name__ == '__main__':
  main()

Of course the workaround is to simply use:

create_engine(uri, connect_args={ 'connect_timeout': 5))

But if you're going to parse some of the documented options for the connector why not them all?

Also this was uncovered in a system where changing the configuration of the system and supplying options via the url was trivial but modifying the code base was exceedingly painful.

Adding the line

    util.coerce_kw_type(opts, 'connect_timeout', int)

to site-packages/sqlalchemy/dialects/mysql/mysqlconnector.py

appears to correct the issue for the 'connect_timeout' args

Comments (5)

  1. Mike Bayer repo owner

    Support all MySQL/Connector int/bool arguments

    Added support for parsing MySQL/Connector boolean and integer arguments within the URL query string: connection_timeout, connect_timeout, pool_size, get_warnings, raise_on_warnings, raw, consume_results, ssl_verify_cert, force_ipv6, pool_reset_session, compress, allow_local_infile, use_pure.

    Change-Id: I2a1a17d13d47d56871bff32e94fdbed8bc003ad7 Fixes: #3787

    → <<cset 16dcc8bec121>>

  2. Mike Bayer repo owner

    Support all MySQL/Connector int/bool arguments

    Added support for parsing MySQL/Connector boolean and integer arguments within the URL query string: connection_timeout, connect_timeout, pool_size, get_warnings, raise_on_warnings, raw, consume_results, ssl_verify_cert, force_ipv6, pool_reset_session, compress, allow_local_infile, use_pure.

    Change-Id: I2a1a17d13d47d56871bff32e94fdbed8bc003ad7 Fixes: #3787 (cherry picked from commit 16dcc8bec1218835590766f0cb2a019a1b30e340)

    → <<cset 126cd6f40cf9>>

  3. andrew_page@harvard.edu reporter

    so... a semi annual, annual review of the connector/dialect options would be completely out of the question?(in that space of 'many' years'). Having someone subscribe to one of the lower volume mailing lists and scanning the subjects occasionally?

    BTW... the connect_timeout option comes in handy. The name seems to be a bit off (MySQL's issue not yours) since someone could infer that it means 'timeout for a connection' when it appears to actually provide a timeout for operations. This can be useful in isolating issues in a 'slow' db or misconfigured DB(which is what we were using it for).

  4. Mike Bayer repo owner

    so... a semi annual, annual review of the connector/dialect options would be completely out of the question?

    if you are volunteering to provide this service then I would be very grateful.

  5. Log in to comment