]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
implement visit_unsupported_compilation for TypeCompiler
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 25 Feb 2021 21:18:12 +0000 (16:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 25 Feb 2021 21:32:19 +0000 (16:32 -0500)
Fixed regression where the "unsupported compilation error" for unknown
datatypes would fail to raise correctly.

Fixes: #5979
Change-Id: I984fe95666813832ab5bdfc568322e2aa7cc3db0

doc/build/changelog/unreleased_14/5979.rst [new file with mode: 0644]
lib/sqlalchemy/sql/compiler.py
test/sql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_14/5979.rst b/doc/build/changelog/unreleased_14/5979.rst
new file mode 100644 (file)
index 0000000..e967140
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, regression, sql
+    :tickets: 5979
+
+    Fixed regression where the "unsupported compilation error" for unknown
+    datatypes would fail to raise correctly.
index 763b4cabbd7cbfd404ef40870300d56c590652bb..c4577e397a76f666f42e4017cce8fb1e9be91073 100644 (file)
@@ -550,6 +550,12 @@ class TypeCompiler(util.with_metaclass(util.EnsureKWArgType, object)):
     def process(self, type_, **kw):
         return type_._compiler_dispatch(self, **kw)
 
+    def visit_unsupported_compilation(self, element, err, **kw):
+        util.raise_(
+            exc.UnsupportedCompilationError(self, element),
+            replace_context=err,
+        )
+
 
 # this was a Visitable, but to allow accurate detection of
 # column elements this is actually a column element
index 140de8622305dc1d5d28619d564f5c9708469875..9e818e997574b34caff2a6a2e6b5a628e7ed374d 100644 (file)
@@ -88,6 +88,7 @@ from sqlalchemy.testing import assert_raises_message
 from sqlalchemy.testing import AssertsCompiledSQL
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import eq_ignore_whitespace
+from sqlalchemy.testing import expect_raises_message
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing import is_
 from sqlalchemy.testing import is_true
@@ -4271,6 +4272,19 @@ class UnsupportedTest(fixtures.TestBase):
             go,
         )
 
+    def test_unsupported_type(self):
+        class MyType(types.TypeEngine):
+            __visit_name__ = "mytype"
+
+        t = Table("t", MetaData(), Column("q", MyType()))
+
+        with expect_raises_message(
+            exc.CompileError,
+            r"\(in table 't', column 'q'\): Compiler .*SQLiteTypeCompiler.* "
+            r"can't render element of type MyType\(\)",
+        ):
+            schema.CreateTable(t).compile(dialect=sqlite.dialect())
+
     def test_unsupported_operator(self):
         from sqlalchemy.sql.expression import BinaryExpression