From: Mike Bayer Date: Thu, 28 Jan 2010 20:30:42 +0000 (+0000) Subject: add an informative error msg for non-collection passed to select() X-Git-Tag: rel_0_6beta1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ca4107c3ed9caff2f6584e4b7215294a6409790;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add an informative error msg for non-collection passed to select() --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 6d74fec168..bf3d16e695 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -3488,8 +3488,14 @@ class Select(_SelectBaseMixin, FromClause): self._correlate = set() self._froms = util.OrderedSet() - - if columns: + + try: + cols_present = bool(columns) + except TypeError: + raise exc.ArgumentError("columns argument to select() must " + "be a Python list or other iterable") + + if cols_present: self._raw_columns = [] for c in columns: c = _literal_as_column(c) diff --git a/test/sql/test_select.py b/test/sql/test_select.py index fd7fb9ceb6..d5ba8fa9e7 100644 --- a/test/sql/test_select.py +++ b/test/sql/test_select.py @@ -81,7 +81,11 @@ class SelectTest(TestBase, AssertsCompiledSQL): self.assert_compile(select([table1, table2]), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, \ myothertable.othername FROM mytable, myothertable") - + + def test_invalid_col_argument(self): + assert_raises(exc.ArgumentError, select, table1) + assert_raises(exc.ArgumentError, select, table1.c.myid) + def test_from_subquery(self): """tests placing select statements in the column clause of another select, for the purposes of selecting from the exported columns of that select."""