summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-02-19 15:18:22 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-02-19 15:18:22 -0500
commit77ed03652580c5db925729c573b76ca32393dc67 (patch)
tree634ae4d06624befb7a20bf22781ffe1c444a7afd
parentdd32540dabbee0678530fb1b0868d1eb41572dca (diff)
downloadsqlalchemy-77ed03652580c5db925729c573b76ca32393dc67.tar.gz
- 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.
-rw-r--r--doc/build/changelog/changelog_08.rst9
-rw-r--r--lib/sqlalchemy/sql/dml.py1
-rw-r--r--test/sql/test_insert.py23
3 files changed, 33 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index 4e91839cc..aabcdf3c8 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -12,6 +12,15 @@
: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
:tickets: 2880, 2964
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py
index 854b894ee..098f2d584 100644
--- a/lib/sqlalchemy/sql/dml.py
+++ b/lib/sqlalchemy/sql/dml.py
@@ -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:
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py
index 5c3b9b6c9..8a5c7cd83 100644
--- a/test/sql/test_insert.py
+++ b/test/sql/test_insert.py
@@ -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'