[Sqlalchemy-tickets] Issue #3943: engine.has_table() throws an error instead of returning False whe
Brought to you by:
zzzeek
From: Nick H. <iss...@bi...> - 2017-03-21 17:27:17
|
New issue 3943: engine.has_table() throws an error instead of returning False when a table does not exist https://bitbucket.org/zzzeek/sqlalchemy/issues/3943/enginehas_table-throws-an-error-instead-of Nick Hahner: Hi there, I've got the following versions: SQLAlchemy==1.1.6 mysql-connector==2.1.4 When running the following code I get an error: ``` #!python import mysql.connector from sqlalchemy import create_engine engine = create_engine('mysql://', creator=lambda: mysql.connector.connect( option_files='/Users/me/.mylogin.cnf' ) ) engine.has_table('table_that_exists', schema='my_schema') # -> returns True engine.has_table('table_that_does_not_exist', schema='my_schema') --------------------------------------------------------------------------- ProgrammingError Traceback (most recent call last) <ipython-input-18-c38b6b523753> in <module>() ----> 1 engine.has_table('table_that_does_not_exist',schema='my_schema') /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in has_table(self, table_name, schema) 2131 2132 """ -> 2133 return self.run_callable(self.dialect.has_table, table_name, schema) 2134 2135 def _wrap_pool_connect(self, fn, connection): /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in run_callable(self, callable_, *args, **kwargs) 2034 """ 2035 with self.contextual_connect() as conn: -> 2036 return conn.run_callable(callable_, *args, **kwargs) 2037 2038 def execute(self, statement, *multiparams, **params): /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in run_callable(self, callable_, *args, **kwargs) 1523 1524 """ -> 1525 return callable_(self, *args, **kwargs) 1526 1527 def _run_visitor(self, visitorcallable, element, **kwargs): /usr/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.pyc in has_table(self, connection, table_name, schema) 1659 try: 1660 rs = connection.execution_options( -> 1661 skip_user_error_events=True).execute(st) 1662 have = rs.fetchone() is not None 1663 rs.close() /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in execute(self, object, *multiparams, **params) 937 """ 938 if isinstance(object, util.string_types[0]): --> 939 return self._execute_text(object, multiparams, params) 940 try: 941 meth = object._execute_on_connection /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_text(self, statement, multiparams, params) 1095 statement, 1096 parameters, -> 1097 statement, parameters 1098 ) 1099 if self._has_events or self.engine._has_events: /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args) 1187 parameters, 1188 cursor, -> 1189 context) 1190 1191 if self._has_events or self.engine._has_events: /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _handle_dbapi_exception(self, e, statement, parameters, cursor, context) 1394 ) 1395 else: -> 1396 util.reraise(*exc_info) 1397 1398 finally: /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args) 1180 statement, 1181 parameters, -> 1182 context) 1183 except BaseException as e: 1184 self._handle_dbapi_exception( /usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.pyc in do_execute(self, cursor, statement, parameters, context) 468 469 def do_execute(self, cursor, statement, parameters, context=None): --> 470 cursor.execute(statement, parameters) 471 472 def do_execute_no_params(self, cursor, statement, context=None): /usr/local/lib/python2.7/site-packages/mysql/connector/cursor.pyc in execute(self, operation, params, multi) 513 else: 514 try: --> 515 self._handle_result(self._connection.cmd_query(stmt)) 516 except errors.InterfaceError: 517 if self._connection._have_next_result: # pylint: disable=W0212 /usr/local/lib/python2.7/site-packages/mysql/connector/connection.pyc in cmd_query(self, query, raw, buffered, raw_as_string) 486 if not isinstance(query, bytes): 487 query = query.encode('utf-8') --> 488 result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) 489 490 if self._have_next_result: /usr/local/lib/python2.7/site-packages/mysql/connector/connection.pyc in _handle_result(self, packet) 393 return self._handle_eof(packet) 394 elif packet[4] == 255: --> 395 raise errors.get_exception(packet) 396 397 # We have a text result set ProgrammingError: 1146 (42S02): Table 'my_schema.table_that_does_not_exist' doesn't exist ``` the ~/.mylogin.cnf' file is an unencrypted config file https://dev.mysql.com/doc/refman/5.7/en/option-files.html |