- changed component to postgres
- assigned issue to
error reporting on cursor.close() hitting a nonexistent attribute
Issue #1786
resolved
Basically, I noticed that if I build a query where (for example) the column is an INT but the value I pass it in something non-INTy (like "green"), I get a totally unexpected error:
row_iterator = conn.execution_options(stream_results=True).execute(query)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1109, in execute
return Connection.executors[c](c)(self, object, multiparams, params)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1186, in _execute_clauseelement
return self.__execute_context(context)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1215, in __execute_context
context.parameters[0](0), context=context)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1284, in _cursor_execute
self._handle_dbapi_exception(e, statement, parameters, cursor, context)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1256, in _handle_dbapi_exception
cursor.close()
File "/usr/lib/python2.6/site-packages/sqlalchemy/pool.py", line 457, in close
self.__parent._logger.warn("Error closing cursor: %s", ex_text)
File "/usr/lib/python2.6/site-packages/sqlalchemy/pool.py", line 469, in __getattr__
return getattr(self.cursor, key)
AttributeError: 'psycopg2._psycopg.cursor' object has no attribute '_CursorFairy__parent'
----------------------------------------
Sorry for the horrible description.
Comments (5)
-
repo owner -
Account Deleted Given a Table object (table) with a column ('some_integer_column') which is of type INTEGER.
If one constructs a query:
query = table.select().where(some_integer_column=='green')
When that query is executed (assuming 'conn' is a Connection instance):
row_iterator = conn.execution_options(stream_results=True).execute(query) for row in row_iterator: print row
If one constructs a query where the column's datatype makes sense:
query = table.select().where(some_integer_column==4)
then everything is OK.
If one does not use
row_iterator = conn.execution_options(stream_results=True).execute(query)
but instead
row_iterator = conn.execute(query)
One gets a DataError exception:
DataError: (DataError) invalid input syntax for integer: "green"
-
repo owner - changed title to error reporting on cursor.close() hitting a nonexistent attribute
- changed component to sql
Here is that test, again:
from sqlalchemy import * engine = create_engine('postgresql://scott:tiger@localhost/test', echo=True) m = MetaData() table = Table('foo', m, Column("some_integer_column", Integer) ) m.create_all(engine) query = table.select().where(table.c.some_integer_column=='green') conn = engine.connect() row_iterator = conn.execution_options(stream_results=True).execute(query) for row in row_iterator: print row
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.6.1 (automated comment)
- Log in to comment
We don't know what a "non-INTy query" is or what that might look like in your specific case. You really have to give us a test case here, else there's little we can do.