diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-12-09 18:15:25 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-12-09 18:15:25 -0500 |
| commit | e57bf796169282f69187f50665f5ea233c2c9ab7 (patch) | |
| tree | 528c1d972372b04bc6044a39c295fdb735298a97 /test/sql | |
| parent | f4a1129e79e0cd938da3e7737b190f7f4db3ed63 (diff) | |
| download | sqlalchemy-e57bf796169282f69187f50665f5ea233c2c9ab7.tar.gz | |
- Fixed issue within the :meth:`.Insert.from_select` construct whereby
the :class:`.Select` construct would have its ``._raw_columns``
collection mutated in-place when compiling the :class:`.Insert`
construct, when the target :class:`.Table` has Python-side defaults.
The :class:`.Select` construct would compile standalone with the
erroneous column present subsequent to compilation of the
:class:`.Insert`, and the the :class:`.Insert` statement itself would
fail on a second compile attempt due to duplicate bound parameters.
fixes #3603
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_insert.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index bdaf4f38c..ea4de032c 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -319,6 +319,32 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): checkparams={"name_1": "foo", "foo": None} ) + def test_insert_from_select_dont_mutate_raw_columns(self): + # test [ticket:3603] + from sqlalchemy import table + table_ = table( + 'mytable', + Column('foo', String), + Column('bar', String, default='baz'), + ) + + stmt = select([table_.c.foo]) + insert = table_.insert().from_select(['foo'], stmt) + + self.assert_compile(stmt, "SELECT mytable.foo FROM mytable") + self.assert_compile( + insert, + "INSERT INTO mytable (foo, bar) " + "SELECT mytable.foo, :bar AS anon_1 FROM mytable" + ) + self.assert_compile(stmt, "SELECT mytable.foo FROM mytable") + self.assert_compile( + insert, + "INSERT INTO mytable (foo, bar) " + "SELECT mytable.foo, :bar AS anon_1 FROM mytable" + ) + + def test_insert_mix_select_values_exception(self): table1 = self.tables.mytable sel = select([table1.c.myid, table1.c.name]).where( |
