]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where calling :meth:`.Insert.values` with an empty list
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 19 Feb 2014 20:18:22 +0000 (15:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 19 Feb 2014 20:18:22 +0000 (15:18 -0500)
or tuple would raise an IndexError.   It now produces an empty
insert construct as would be the case with an empty dictionary.

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/dml.py
test/sql/test_insert.py

index 4e91839cc5dc69590c86952ac5ca987cedd6a171..aabcdf3c857bb151b8718dda9b71c55cab71f447 100644 (file)
 .. changelog::
     :version: 0.8.5
 
+     .. change::
+        :tags: bug, sql
+        :versions: 0.9.3
+        :tickets: 2944
+
+        Fixed bug where calling :meth:`.Insert.values` with an empty list
+        or tuple would raise an IndexError.   It now produces an empty
+        insert construct as would be the case with an empty dictionary.
+
      .. change::
         :tags: bug, engine, pool
         :versions: 0.9.3
index 854b894ee64cbca5c30e3d8bfe1b6b68729704f4..098f2d58424276db916b8c058081fa47eb3ac24d 100644 (file)
@@ -37,6 +37,7 @@ class UpdateBase(DialectKWArgs, HasPrefixes, Executable, ClauseElement):
                 return p
 
         if isinstance(parameters, (list, tuple)) and \
+                parameters and \
               isinstance(parameters[0], (list, tuple, dict)):
 
             if not self._supports_multi_parameters:
index 5c3b9b6c98641029a63aaf9c544334bbba9753df..8a5c7cd83b4fc165897951a1198070c4991083fc 100644 (file)
@@ -244,6 +244,29 @@ class EmptyTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
                 "settings does not support empty inserts.",
             stmt.compile, dialect=dialect)
 
+    def _test_insert_with_empty_collection_values(self, collection):
+        table1 = self.tables.mytable
+
+        ins = table1.insert().values(collection)
+
+        self.assert_compile(ins,
+            'INSERT INTO mytable () VALUES ()',
+            checkparams={})
+
+        # empty dict populates on next values call
+        self.assert_compile(ins.values(myid=3),
+            'INSERT INTO mytable (myid) VALUES (:myid)',
+            checkparams={'myid': 3})
+
+    def test_insert_with_empty_list_values(self):
+        self._test_insert_with_empty_collection_values([])
+
+    def test_insert_with_empty_dict_values(self):
+        self._test_insert_with_empty_collection_values({})
+
+    def test_insert_with_empty_tuple_values(self):
+        self._test_insert_with_empty_collection_values(())
+
 
 class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
     __dialect__ = 'default'