]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix type string formatting calls
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Mar 2022 22:17:53 +0000 (17:17 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Mar 2022 22:17:53 +0000 (17:17 -0500)
Fixed type-related error messages that would fail for values that were
tuples, due to string formatting syntax, including compile of unsupported
literal values and invalid boolean values.

Fixes: #7721
Change-Id: I6775721486ef2db2d0738b9aa08b9f2570f55659

doc/build/changelog/unreleased_14/7721.rst [new file with mode: 0644]
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_types.py

diff --git a/doc/build/changelog/unreleased_14/7721.rst b/doc/build/changelog/unreleased_14/7721.rst
new file mode 100644 (file)
index 0000000..d719e22
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, sql
+    :tickets: 7721
+
+    Fixed type-related error messages that would fail for values that were
+    tuples, due to string formatting syntax, including compile of unsupported
+    literal values and invalid boolean values.
index 3794fd8f793c80e7363456280f83336528a47237..bf5f1dc1bc587d47c3d2ec839ce5674d4d972e9f 100644 (file)
@@ -1755,10 +1755,10 @@ class Boolean(Emulated, TypeEngine[bool], SchemaType):
     def _strict_as_bool(self, value):
         if value not in self._strict_bools:
             if not isinstance(value, int):
-                raise TypeError("Not a boolean value: %r" % value)
+                raise TypeError("Not a boolean value: %r" % (value,))
             else:
                 raise ValueError(
-                    "Value %r is not None, True, or False" % value
+                    "Value %r is not None, True, or False" % (value,)
                 )
         return value
 
@@ -3087,7 +3087,7 @@ class NullType(TypeEngine):
     def literal_processor(self, dialect):
         def process(value):
             raise exc.CompileError(
-                "Don't know how to render literal SQL value: %r" % value
+                "Don't know how to render literal SQL value: %r" % (value,)
             )
 
         return process
@@ -3181,7 +3181,7 @@ def _resolve_value_to_type(value):
             insp.__class__ in inspection._registrars
         ):
             raise exc.ArgumentError(
-                "Object %r is not legal as a SQL literal value" % value
+                "Object %r is not legal as a SQL literal value" % (value,)
             )
         return NULLTYPE
     else:
index 58dfa4dd8aee64cab367cad201ba2794f36530c3..223f367b1f79e16688991d73856ced3f447c4ac5 100644 (file)
@@ -3422,6 +3422,23 @@ class ExpressionTest(
 class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = "default"
 
+    def test_compile_err_formatting(self):
+        with expect_raises_message(
+            exc.CompileError,
+            r"Don't know how to render literal SQL value: \(1, 2, 3\)",
+        ):
+            func.foo((1, 2, 3)).compile(compile_kwargs={"literal_binds": True})
+
+    def test_strict_bool_err_formatting(self):
+        typ = Boolean()
+
+        dialect = default.DefaultDialect()
+        with expect_raises_message(
+            TypeError,
+            r"Not a boolean value: \(5,\)",
+        ):
+            typ.bind_processor(dialect)((5,))
+
     @testing.requires.unbounded_varchar
     def test_string_plain(self):
         self.assert_compile(String(), "VARCHAR")