From 6cd195c4a1589620784b052a041e691427d1e086 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 25 Feb 2021 16:18:12 -0500 Subject: [PATCH] implement visit_unsupported_compilation for TypeCompiler 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 | 6 ++++++ lib/sqlalchemy/sql/compiler.py | 6 ++++++ test/sql/test_compiler.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 doc/build/changelog/unreleased_14/5979.rst diff --git a/doc/build/changelog/unreleased_14/5979.rst b/doc/build/changelog/unreleased_14/5979.rst new file mode 100644 index 0000000000..e9671409ba --- /dev/null +++ b/doc/build/changelog/unreleased_14/5979.rst @@ -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. diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 763b4cabbd..c4577e397a 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -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 diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 140de86223..9e818e9975 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -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 -- 2.47.2