summaryrefslogtreecommitdiff
path: root/test/sql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-11-14 08:54:56 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-11-14 10:28:40 -0500
commiteea0f44bbdb759368996dcdb241e837c7c809fb9 (patch)
tree12ecc66f8183896b833a08c90ebf39799610d816 /test/sql/test_compiler.py
parent9f4ac8d155f58b59cf314cfbc73195ed51a0c146 (diff)
downloadsqlalchemy-eea0f44bbdb759368996dcdb241e837c7c809fb9.tar.gz
add informative exception context for literal render
An informative re-raise is now thrown in the case where any "literal bindparam" render operation fails, indicating the value itself and the datatype in use, to assist in debugging when literal params are being rendered in a statement. Fixes: #8800 Change-Id: Id658f8b03359312353ddbb0c7563026239579f7b
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r--test/sql/test_compiler.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 97b1b9124..4eea11795 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -98,6 +98,7 @@ from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
from sqlalchemy.testing import ne_
from sqlalchemy.testing.schema import pep435_enum
+from sqlalchemy.types import UserDefinedType
table1 = table(
"mytable",
@@ -4609,6 +4610,51 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase):
"OR mytable.myid = :myid_2 OR mytable.myid = :myid_3",
)
+ @testing.combinations("plain", "expanding", argnames="exprtype")
+ def test_literal_bind_typeerror(self, exprtype):
+ """test #8800"""
+
+ if exprtype == "expanding":
+ stmt = select(table1).where(
+ table1.c.myid.in_([("tuple",), ("tuple",)])
+ )
+ elif exprtype == "plain":
+ stmt = select(table1).where(table1.c.myid == ("tuple",))
+ else:
+ assert False
+
+ with expect_raises_message(
+ exc.CompileError,
+ r"Could not render literal value \"\(\'tuple\',\)\" "
+ r"with datatype INTEGER; see parent "
+ r"stack trace for more detail.",
+ ):
+ stmt.compile(compile_kwargs={"literal_binds": True})
+
+ @testing.combinations("plain", "expanding", argnames="exprtype")
+ def test_literal_bind_dont_know_how_to_quote(self, exprtype):
+ """test #8800"""
+
+ class MyType(UserDefinedType):
+ def get_col_spec(self, **kw):
+ return "MYTYPE"
+
+ col = column("x", MyType())
+
+ if exprtype == "expanding":
+ stmt = select(table1).where(col.in_([("tuple",), ("tuple",)]))
+ elif exprtype == "plain":
+ stmt = select(table1).where(col == ("tuple",))
+ else:
+ assert False
+
+ with expect_raises_message(
+ exc.CompileError,
+ r"No literal value renderer is available for literal "
+ r"value \"\('tuple',\)\" with datatype MYTYPE",
+ ):
+ stmt.compile(compile_kwargs={"literal_binds": True})
+
@testing.fixture
def ansi_compiler_fixture(self):
dialect = default.DefaultDialect()