New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed. when mysql fetch result None crash #369
Conversation
item = self.rowproxy[index] TypeError: 'NoneType' object has no attribute '__getitem__'
hi there - row.fetchone() will never be None, and if it is, that's a bug elsewhere. silently skipping here will just cause more failures. can you please illustrate a complete test case that shows how this value becomes None? |
error cause on mysql version 5.7.18 Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> engine = sqlalchemy.create_engine('mysql://root:@localhost/traffic?charset=utf8')
>>> conn = engine.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2091, in connect
return self._connection_cls(self, **kwargs)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 90, in __init__
if connection is not None else engine.raw_connection()
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2177, in raw_connection
self.pool.unique_connection, _connection)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
return fn()
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 328, in unique_connection
return _ConnectionFairy._checkout(self)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 516, in checkout
rec = pool._do_get()
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1138, in _do_get
self._dec_overflow()
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1135, in _do_get
return self._create_connection()
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 333, in _create_connection
return _ConnectionRecord(self)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 461, in __init__
self.__connect(first_connect_check=True)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/pool.py", line 661, in __connect
exec_once(self.connection, self)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 246, in exec_once
self(*args, **kw)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 256, in __call__
fn(*args, **kw)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 1331, in go
return once_fn(*arg, **kw)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 181, in first_connect
dialect.initialize(c)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 1698, in initialize
self._detect_ansiquotes(connection)
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 1975, in _detect_ansiquotes
mode = row[1] or ''
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 2062, in __getitem__
item = self.rowproxy[index]
TypeError: 'NoneType' object has no attribute '__getitem__'
>>> |
Fixed. the _compat_fist and test the _compat_fetchone mysql> select * from `instance_status_history`;
Empty set (0.00 sec)
mysql> Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> engine = sqlalchemy.create_engine('mysql://root:@localhost/traffic?charset=utf8')
>>> conn = engine.connect()
>>> rp = conn.execute('select * from `instance_status_history`')
>>> row = rp.dialect._compat_fetchone(rp)
>>> row[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lmj/repo/nupic/venv-test/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 2064, in __getitem__
item = self.rowproxy[index]
TypeError: 'NoneType' object has no attribute '__getitem__'
>>> |
mmmm still need to see what MySQL Python version you have, run this:
Also go onto your database and show me the output of this:
"sql_mode" is always present, if something weird is going on on your database where this is not coming back, we have to fix this elsewhere (e.g. we should not be calling _compat_first()). |
$ python -c "import MySQLdb; print(MySQLdb.__version__)"
1.2.5 $ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4269
Server version: 5.7.18 Homebrew
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'sql_mode';
Empty set (0.00 sec)
mysql> |
OK. can you show me the output of "SHOW VARIABLES" just plain? also log in as root, and do "SHOW GRANTS FOR " with the user you're logging in as? if theres a case where a logged in user can't see VARIABLES that is a new bug report. |
issue created at https://bitbucket.org/zzzeek/sqlalchemy/issues/4007/mysql-57-may-have-made-show-variables as this looks like a regression due to changes in MySQL. |
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9857
Server version: 5.7.18 Homebrew
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW VARIABLES;
Empty set (0.00 sec)
mysql> SHOW GRANTS FOR;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql>
|
resolved in 5650a0c |
when mysql fetch result is None getitem crash