[Sqlalchemy-tickets] Issue #3450: Accessing iterator on a query that has an error shows as not iter
Brought to you by:
zzzeek
|
From: Michael B. <iss...@bi...> - 2015-06-12 15:39:08
|
New issue 3450: Accessing iterator on a query that has an error shows as not iterable https://bitbucket.org/zzzeek/sqlalchemy/issue/3450/accessing-iterator-on-a-query-that-has-an Michael Brown: Found on 1.0.3 and 1.0.4 I have a query that when evaluated throws a SQL error, except if the iterator is used. If the iterator is used then it shows as not iterable: Normal: ``` In [66]: q = session.query(m.Panel).filter(m.Panel.ptype=='blood') In [67]: map(lambda x: x, q) Out[67]: [Panel(ptype='blood', id=74, name='bottle'), Panel(ptype='blood', id=75, name='space shuttle'), Panel(ptype='blood', id=76, name='russian'), … ``` Failing: ``` In [68]: q = session.query(m.Panel).filter(m.Panel.ptype=='bloody') In [69]: next(q) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) panel.py in <module>() ----> 1 next(q) TypeError: Query object is not an iterator ``` What I think *should* happen is that the underlying error should be thrown like so when the iterator gets accessed (note the Query still shows as Iterable): ``` In [70]: q.first() --------------------------------------------------------------------------- DataError Traceback (most recent call last) … DataError: (psycopg2.DataError) invalid input value for enum panel_type: "bloody" ``` |