]> 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:48:53 +0000 (17:48 -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
(cherry picked from commit a261a78894c4f835b5da7fcbfb3d466a687bc11b)

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 726313fcf405067312e460c67b7692de8d3f9cd9..72b7a2899a1b8c060505a5c95c7ad171ee6fad48 100644 (file)
@@ -1973,10 +1973,10 @@ class Boolean(Emulated, TypeEngine, 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
 
@@ -3220,7 +3220,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
@@ -3315,7 +3315,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 8530b904331558c1735401244ed2a2b8ce4f215b..d164de4ec6f48c13a8ea0b0e8db5cfc484758c12 100644 (file)
@@ -82,6 +82,7 @@ from sqlalchemy.testing import engines
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import expect_deprecated_20
 from sqlalchemy.testing import expect_raises
+from sqlalchemy.testing import expect_raises_message
 from sqlalchemy.testing import expect_warnings
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing import is_
@@ -3457,6 +3458,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")