summaryrefslogtreecommitdiff
path: root/test/sql/test_lambdas.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-12-03 14:04:05 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-12-06 18:27:19 -0500
commit22deafe15289d2be55682e1632016004b02b62c0 (patch)
tree5b521531418aebd4e293f848ebe4accbbd9bc5bc /test/sql/test_lambdas.py
parente88dc004e6bcd1418cb8eb811d0aa580c2a44b8f (diff)
downloadsqlalchemy-22deafe15289d2be55682e1632016004b02b62c0.tar.gz
Warn when caching is disabled / document
This patch adds new warnings for all elements that don't indicate their caching behavior, including user-defined ClauseElement subclasses and third party dialects. it additionally adds new documentation to discuss an apparent performance degradation in 1.4 when caching is disabled as a result in the significant expense incurred by ORM lazy loaders, which in 1.3 used BakedQuery so were actually cached. As a result of adding the warnings, a fair degree of lesser used SQL expression objects identified that they did not define caching behavior so would have been producing ``[no key]``, including PostgreSQL constructs ``hstore`` and ``array``. These have been amended to use inherit cache where appropriate. "on conflict" constructs in PostgreSQL, MySQL, SQLite still explicitly don't generate a cache key at this time. The change also adds a test for all constructs via assert_compile() to assert they will not generate cache warnings. Fixes: #7394 Change-Id: I85958affbb99bfad0f5efa21bc8f2a95e7e46981
Diffstat (limited to 'test/sql/test_lambdas.py')
-rw-r--r--test/sql/test_lambdas.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/test/sql/test_lambdas.py b/test/sql/test_lambdas.py
index fd6b1eb41..bbf9716f5 100644
--- a/test/sql/test_lambdas.py
+++ b/test/sql/test_lambdas.py
@@ -17,6 +17,7 @@ from sqlalchemy.sql import roles
from sqlalchemy.sql import select
from sqlalchemy.sql import table
from sqlalchemy.sql import util as sql_util
+from sqlalchemy.sql.base import ExecutableOption
from sqlalchemy.sql.traversals import HasCacheKey
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
@@ -810,7 +811,10 @@ class LambdaElementTest(
stmt = lambdas.lambda_stmt(lambda: select(column("x")))
- opts = {column("x"), column("y")}
+ class MyUncacheable(ExecutableOption):
+ pass
+
+ opts = {MyUncacheable()}
assert_raises_message(
exc.InvalidRequestError,
@@ -942,11 +946,18 @@ class LambdaElementTest(
return stmt
- s1 = go([column("a"), column("b")])
+ class SomeOpt(HasCacheKey, ExecutableOption):
+ def __init__(self, x):
+ self.x = x
+
+ def _gen_cache_key(self, anon_map, bindparams):
+ return (SomeOpt, self.x)
+
+ s1 = go([SomeOpt("a"), SomeOpt("b")])
- s2 = go([column("a"), column("b")])
+ s2 = go([SomeOpt("a"), SomeOpt("b")])
- s3 = go([column("q"), column("b")])
+ s3 = go([SomeOpt("q"), SomeOpt("b")])
s1key = s1._generate_cache_key()
s2key = s2._generate_cache_key()
@@ -964,7 +975,7 @@ class LambdaElementTest(
return stmt
- class SomeOpt(HasCacheKey):
+ class SomeOpt(HasCacheKey, ExecutableOption):
def _gen_cache_key(self, anon_map, bindparams):
return ("fixed_key",)
@@ -994,8 +1005,8 @@ class LambdaElementTest(
return stmt
- class SomeOpt(HasCacheKey):
- pass
+ class SomeOpt(HasCacheKey, ExecutableOption):
+ inherit_cache = False
# generates no key, will not be cached
eq_(SomeOpt()._generate_cache_key(), None)