]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add an informative error msg for non-collection passed to select()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jan 2010 20:30:42 +0000 (20:30 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jan 2010 20:30:42 +0000 (20:30 +0000)
lib/sqlalchemy/sql/expression.py
test/sql/test_select.py

index 6d74fec16885015c2cd046f8fdc4f70b97fb803c..bf3d16e695f252487fe2c251d434efe8bd50a697 100644 (file)
@@ -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)
index fd7fb9ceb65f6028526dd1029110e98d37300af7..d5ba8fa9e73fa8a4e534d59bdad9c5f063e847ca 100644 (file)
@@ -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."""