summaryrefslogtreecommitdiff
path: root/test/sql/test_functions.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_functions.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_functions.py')
-rw-r--r--test/sql/test_functions.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index 9378cfc38..e08526419 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -81,6 +81,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
# test generic function compile
class fake_func(GenericFunction):
+ inherit_cache = True
__return_type__ = sqltypes.Integer
def __init__(self, arg, **kwargs):
@@ -107,6 +108,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
if use_custom:
class MyFunc(FunctionElement):
+ inherit_cache = True
name = "myfunc"
type = Integer()
@@ -135,6 +137,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_use_labels_function_element(self):
class max_(FunctionElement):
name = "max"
+ inherit_cache = True
@compiles(max_)
def visit_max(element, compiler, **kw):
@@ -260,7 +263,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_default_namespace(self):
class myfunc(GenericFunction):
- pass
+ inherit_cache = True
assert isinstance(func.myfunc(), myfunc)
self.assert_compile(func.myfunc(), "myfunc()")
@@ -268,6 +271,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_type(self):
class myfunc(GenericFunction):
type = DateTime
+ inherit_cache = True
assert isinstance(func.myfunc().type, DateTime)
self.assert_compile(func.myfunc(), "myfunc()")
@@ -275,12 +279,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_legacy_type(self):
# in case someone was using this system
class myfunc(GenericFunction):
+ inherit_cache = True
__return_type__ = DateTime
assert isinstance(func.myfunc().type, DateTime)
def test_case_sensitive(self):
class MYFUNC(GenericFunction):
+ inherit_cache = True
type = DateTime
assert isinstance(func.MYFUNC().type, DateTime)
@@ -336,6 +342,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_w_custom_name(self):
class myfunc(GenericFunction):
+ inherit_cache = True
name = "notmyfunc"
assert isinstance(func.notmyfunc(), myfunc)
@@ -343,6 +350,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_w_quoted_name(self):
class myfunc(GenericFunction):
+ inherit_cache = True
name = quoted_name("NotMyFunc", quote=True)
identifier = "myfunc"
@@ -350,6 +358,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_w_quoted_name_no_identifier(self):
class myfunc(GenericFunction):
+ inherit_cache = True
name = quoted_name("NotMyFunc", quote=True)
# note this requires that the quoted name be lower cased for
@@ -359,6 +368,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_package_namespace(self):
def cls1(pk_name):
class myfunc(GenericFunction):
+ inherit_cache = True
package = pk_name
return myfunc
@@ -372,6 +382,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_name(self):
class MyFunction(GenericFunction):
name = "my_func"
+ inherit_cache = True
def __init__(self, *args):
args = args + (3,)
@@ -387,20 +398,24 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
package = "geo"
name = "BufferOne"
identifier = "buf1"
+ inherit_cache = True
class GeoBuffer2(GenericFunction):
type = Integer
name = "BufferTwo"
identifier = "buf2"
+ inherit_cache = True
class BufferThree(GenericFunction):
type = Integer
identifier = "buf3"
+ inherit_cache = True
class GeoBufferFour(GenericFunction):
type = Integer
name = "BufferFour"
identifier = "Buf4"
+ inherit_cache = True
self.assert_compile(func.geo.buf1(), "BufferOne()")
self.assert_compile(func.buf2(), "BufferTwo()")
@@ -413,7 +428,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
def test_custom_args(self):
class myfunc(GenericFunction):
- pass
+ inherit_cache = True
self.assert_compile(
myfunc(1, 2, 3), "myfunc(:myfunc_1, :myfunc_2, :myfunc_3)"
@@ -1010,6 +1025,7 @@ class ExecuteTest(fixtures.TestBase):
from sqlalchemy.ext.compiler import compiles
class myfunc(FunctionElement):
+ inherit_cache = True
type = Date()
@compiles(myfunc)