summaryrefslogtreecommitdiff
path: root/test/sql/test_insert.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-09-21 22:35:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-09-21 22:36:27 -0400
commite1f316fe7f51671c1eca8ebfacf4267b2bb0a44c (patch)
tree8224d3786d0cad9513dfb3758286d505526f36b7 /test/sql/test_insert.py
parentd09065d43d9914a1db45b89bd845072d7970155f (diff)
downloadsqlalchemy-e1f316fe7f51671c1eca8ebfacf4267b2bb0a44c.tar.gz
coerce for multivalues keys
Fixed issue where using ORM column expressions as keys in the list of dictionaries passed to :meth:`_sql.Insert.values` for "multi-valued insert" would not be processed correctly into the correct column expressions. Fixes: #7060 Change-Id: I1c4c286c33ea6eeaafba617996828f5c88ff0a1c
Diffstat (limited to 'test/sql/test_insert.py')
-rw-r--r--test/sql/test_insert.py58
1 files changed, 50 insertions, 8 deletions
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py
index 6c2a5d955..51045daac 100644
--- a/test/sql/test_insert.py
+++ b/test/sql/test_insert.py
@@ -28,6 +28,14 @@ from sqlalchemy.testing import expect_warnings
from sqlalchemy.testing import fixtures
+class ORMExpr(object):
+ def __init__(self, col):
+ self.col = col
+
+ def __clause_element__(self):
+ return self.col
+
+
class _InsertTestBase(object):
@classmethod
def define_tables(cls, metadata):
@@ -1126,13 +1134,33 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
dialect=dialect,
)
- def test_named_with_column_objects(self):
+ @testing.combinations(("strings",), ("columns",), ("inspectables",))
+ def test_named_with_column_objects(self, column_style):
table1 = self.tables.mytable
+ if column_style == "strings":
+ myid, name, description = "myid", "name", "description"
+
+ elif column_style == "columns":
+ myid, name, description = (
+ table1.c.myid,
+ table1.c.name,
+ table1.c.description,
+ )
+ elif column_style == "inspectables":
+
+ myid, name, description = (
+ ORMExpr(table1.c.myid),
+ ORMExpr(table1.c.name),
+ ORMExpr(table1.c.description),
+ )
+ else:
+ assert False
+
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"},
+ {myid: 1, name: "a", description: "b"},
+ {myid: 2, name: "c", description: "d"},
+ {myid: 3, name: "e", description: "f"},
]
checkparams = {
@@ -1304,7 +1332,8 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
dialect=postgresql.dialect(),
)
- def test_python_scalar_default(self):
+ @testing.combinations(("strings",), ("columns",), ("inspectables",))
+ def test_python_scalar_default(self, key_type):
metadata = MetaData()
table = Table(
"sometable",
@@ -1314,10 +1343,23 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
Column("foo", Integer, default=10),
)
+ if key_type == "strings":
+ id_, data, foo = "id", "data", "foo"
+ elif key_type == "columns":
+ id_, data, foo = table.c.id, table.c.data, table.c.foo
+ elif key_type == "inspectables":
+ id_, data, foo = (
+ ORMExpr(table.c.id),
+ ORMExpr(table.c.data),
+ ORMExpr(table.c.foo),
+ )
+ else:
+ assert False
+
values = [
- {"id": 1, "data": "data1"},
- {"id": 2, "data": "data2", "foo": 15},
- {"id": 3, "data": "data3"},
+ {id_: 1, data: "data1"},
+ {id_: 2, data: "data2", foo: 15},
+ {id_: 3, data: "data3"},
]
checkparams = {