From: Mike Bayer Date: Fri, 24 Jan 2014 15:43:43 +0000 (-0500) Subject: - Calling :func:`.bulk_insert` with an empty list will not emit any X-Git-Tag: rel_0_6_3~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dccc55815315158546cf25eb6396721ace7d4885;p=thirdparty%2Fsqlalchemy%2Falembic.git - 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. --- diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index aae10060..4b85a001 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -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): diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index df789837..508f293d 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -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 diff --git a/tests/test_bulk_insert.py b/tests/test_bulk_insert.py index a3fe28c2..8133a296 100644 --- a/tests/test_bulk_insert.py +++ b/tests/test_bulk_insert.py @@ -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_(