]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Calling :func:`.bulk_insert` with an empty list will not emit any
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Jan 2014 15:43:43 +0000 (10:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Jan 2014 15:43:43 +0000 (10:43 -0500)
commands on the current connection.  This was already the case with
``--sql`` mode, so is now the case with "online" mode.

alembic/ddl/impl.py
docs/build/changelog.rst
tests/test_bulk_insert.py

index aae10060c6e9843104d048908c4fd32e5c876132..4b85a00144fb281e00ebff8f679549cfeed9a513 100644 (file)
@@ -178,7 +178,8 @@ class DefaultImpl(with_metaclass(ImplMeta)):
             # work around http://www.sqlalchemy.org/trac/ticket/2461
             if not hasattr(table, '_autoincrement_column'):
                 table._autoincrement_column = None
-            self._exec(table.insert(inline=True), multiparams=rows)
+            if rows:
+                self._exec(table.insert(inline=True), multiparams=rows)
 
     def compare_type(self, inspector_column, metadata_column):
 
index df7898374c35db10567f137b4f6f57ba045307b7..508f293d708c9c18f825a341fad8fe01698440c9 100644 (file)
@@ -5,6 +5,14 @@ Changelog
 .. changelog::
     :version: 0.6.3
 
+    .. change::
+      :tags: bug
+      :tickets: 168
+
+      Calling :func:`.bulk_insert` with an empty list will not emit any
+      commands on the current connection.  This was already the case with
+      ``--sql`` mode, so is now the case with "online" mode.
+
     .. change::
       :tags: bug
       :pullreq: bitbucket:17
index a3fe28c2fa1de19c5571e77ad1bfcc40b921173e..8133a2969fb99f6926af60798a25564189731b59 100644 (file)
@@ -72,6 +72,12 @@ def test_bulk_insert_wrong_cols():
         'INSERT INTO ins_table (id, v1, v2) VALUES (%(id)s, %(v1)s, %(v2)s)'
     )
 
+def test_bulk_insert_no_rows():
+    context, t1 = _table_fixture('default', False)
+
+    op.bulk_insert(t1, [])
+    context.assert_()
+
 def test_bulk_insert_pg():
     context = _test_bulk_insert('postgresql', False)
     context.assert_(