summaryrefslogtreecommitdiff
path: root/test/sql/test_utils.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-04-01 11:56:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2023-04-26 15:45:04 -0400
commit8ec396873c9bbfcc4416e55b5f9d8653554a1df0 (patch)
tree562d185c64995b99b6c854b337f64d48f692b495 /test/sql/test_utils.py
parent32a17e60ba63f0278a754e1ab7e9ebf9460e07c5 (diff)
downloadsqlalchemy-8ec396873c9bbfcc4416e55b5f9d8653554a1df0.tar.gz
support parameters in all ORM insert modes
Fixed 2.0 regression where use of :func:`_sql.bindparam()` inside of :meth:`_dml.Insert.values` would fail to be interpreted correctly when executing the :class:`_dml.Insert` statement using the ORM :class:`_orm.Session`, due to the new ORM-enabled insert feature not implementing this use case. In addition, the bulk INSERT and UPDATE features now add these capabilities: * The requirement that extra parameters aren't passed when using ORM INSERT using the "orm" dml_strategy setting is lifted. * The requirement that additional WHERE criteria is not passed when using ORM UPDATE using the "bulk" dml_strategy setting is lifted. Note that in this case, the check for expected row count is turned off. Fixes: #9583 Change-Id: I539c18893b697caeab5a5f0195a27d4f0487e728
Diffstat (limited to 'test/sql/test_utils.py')
-rw-r--r--test/sql/test_utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/sql/test_utils.py b/test/sql/test_utils.py
index 61777def5..615995c73 100644
--- a/test/sql/test_utils.py
+++ b/test/sql/test_utils.py
@@ -1,5 +1,6 @@
from itertools import zip_longest
+from sqlalchemy import bindparam
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import MetaData
@@ -7,6 +8,7 @@ from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import testing
+from sqlalchemy import TypeDecorator
from sqlalchemy.sql import base as sql_base
from sqlalchemy.sql import coercions
from sqlalchemy.sql import column
@@ -18,6 +20,8 @@ from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import eq_
from sqlalchemy.testing import expect_raises_message
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing import is_
+from sqlalchemy.testing import is_not_none
class MiscTest(fixtures.TestBase):
@@ -41,6 +45,28 @@ class MiscTest(fixtures.TestBase):
eq_(set(sql_util.find_tables(subset_select)), {common})
+ @testing.variation("has_cache_key", [True, False])
+ def test_get_embedded_bindparams(self, has_cache_key):
+ bp = bindparam("x")
+
+ if not has_cache_key:
+
+ class NotCacheable(TypeDecorator):
+ impl = String
+ cache_ok = False
+
+ stmt = select(column("q", NotCacheable())).where(column("y") == bp)
+
+ else:
+ stmt = select(column("q")).where(column("y") == bp)
+
+ eq_(stmt._get_embedded_bindparams(), [bp])
+
+ if not has_cache_key:
+ is_(stmt._generate_cache_key(), None)
+ else:
+ is_not_none(stmt._generate_cache_key())
+
def test_find_tables_aliases(self):
metadata = MetaData()
common = Table(