[Sqlalchemy-tickets] Issue #3787: Mysql Dialect Not Parsing 'connect_timeout' query string param Op
Brought to you by:
zzzeek
From: <and...@ha...> - 2016-09-01 12:48:43
|
New issue 3787: Mysql Dialect Not Parsing 'connect_timeout' query string param Option https://bitbucket.org/zzzeek/sqlalchemy/issues/3787/mysql-dialect-not-parsing-connect_timeout and...@ha...: ``` #!python 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: ``` #!python 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 ``` #!python 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 |