]> 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:23:04 +0000 (15:23 -0500)
or tuple would raise an IndexError.   It now produces an empty
insert construct as would be the case with an empty dictionary.

Conflicts:
lib/sqlalchemy/sql/dml.py

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

index 3484c94c0a44c74aa302921a430fd14b7bed8248..5e67ee8d3377e5a0aea8eae06cf5dda56160f217 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 287707c327b5099aac9593a908c89fe803486858..3d846923573aa53cab3858a7fe3109741af47b25 100644 (file)
@@ -6707,6 +6707,7 @@ class UpdateBase(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'