ValuesBase.values inconsistency fix

Fixed bug in :meth:`.Insert.values` where using the "multi-values"
format in combination with :class:`.Column` objects as keys rather
than strings would fail.   Pull request courtesy Aubrey Stark-Toller.

Change-Id: I9d3b40b5950df8f5bfdc8b1d22f9c3afb277f17f
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/412
Fixes: #4162
(cherry picked from commit ab2165e6d6)
This commit is contained in:
Aubrey Stark-Toller
2018-01-05 15:06:23 -05:00
committed by Mike Bayer
parent 386d52aeb8
commit 8e112ad2cc
3 changed files with 63 additions and 17 deletions
+33
View File
@@ -839,6 +839,39 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
checkparams=checkparams,
dialect=dialect)
def test_named_with_column_objects(self):
table1 = self.tables.mytable
values = [
{table1.c.myid: 1, table1.c.name: 'a', table1.c.description: 'b'},
{table1.c.myid: 2, table1.c.name: 'c', table1.c.description: 'd'},
{table1.c.myid: 3, table1.c.name: 'e', table1.c.description: 'f'},
]
checkparams = {
'myid_m0': 1,
'myid_m1': 2,
'myid_m2': 3,
'name_m0': 'a',
'name_m1': 'c',
'name_m2': 'e',
'description_m0': 'b',
'description_m1': 'd',
'description_m2': 'f',
}
dialect = default.DefaultDialect()
dialect.supports_multivalues_insert = True
self.assert_compile(
table1.insert().values(values),
'INSERT INTO mytable (myid, name, description) VALUES '
'(:myid_m0, :name_m0, :description_m0), '
'(:myid_m1, :name_m1, :description_m1), '
'(:myid_m2, :name_m2, :description_m2)',
checkparams=checkparams,
dialect=dialect)
def test_positional(self):
table1 = self.tables.mytable