[Sqlalchemy-tickets] [sqlalchemy] #2944: Confusing error message when passing empty list to Insert.
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2014-02-07 20:49:57
|
#2944: Confusing error message when passing empty list to Insert.values()
--------------------+-----------------------------------------
Reporter: jet57 | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone:
Component: (none) | Severity: no triage selected yet
Keywords: | Progress State: awaiting triage
--------------------+-----------------------------------------
When passing a list of dictionaries to Insert.values(), I happened to pass
an empty list, as in the following test case:
{{{
#!/usr/bin/python
import sqlalchemy
print sqlalchemy.__version__
from sqlalchemy import Table, Column, Integer, MetaData, insert
m = MetaData()
c1 = Column('c1', Integer)
t1 = Table('t1', m, c1)
s = t1.insert().values([])
}}}
and obtained the following exception:
{{{
0.9.0b1
Traceback (most recent call last):
File "sqlalchemybug.py", line 11, in <module>
s = t1.insert().values([])
File "<string>", line 1, in <lambda>
File "/usr/local/lib/python2.7/dist-
packages/SQLAlchemy-0.9.0b1-py2.7.egg/sqlalchemy/sql/base.py", line 42, in
_generative
fn(self, *args[1:], **kw)
File "/usr/local/lib/python2.7/dist-
packages/SQLAlchemy-0.9.0b1-py2.7.egg/sqlalchemy/sql/dml.py", line 283, in
values
self._process_colparams(v)
File "/usr/local/lib/python2.7/dist-
packages/SQLAlchemy-0.9.0b1-py2.7.egg/sqlalchemy/sql/dml.py", line 41, in
_process_colparams
isinstance(parameters[0], (list, tuple, dict)):
IndexError: list index out of range
}}}
Upon checking the documentation I note that it does say "This mode is
indicated by passing a list of ''one or more'' dictionaries/tuples", i.e.
behaviour on a list of zero dictionaries/tuples is undefined. I feel this
warrants a more explicit error message, rather than letting the
{{{IndexError}}} bubble up.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2944>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|