summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-02-25 16:18:12 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-25 16:32:19 -0500
commit6cd195c4a1589620784b052a041e691427d1e086 (patch)
tree13170d68f7eec9b15cc6fb477aed92dd29846bb5
parentdc615763d39916e9c037c7c376db1817cdf02764 (diff)
downloadsqlalchemy-6cd195c4a1589620784b052a041e691427d1e086.tar.gz
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
-rw-r--r--doc/build/changelog/unreleased_14/5979.rst6
-rw-r--r--lib/sqlalchemy/sql/compiler.py6
-rw-r--r--test/sql/test_compiler.py14
3 files changed, 26 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/5979.rst b/doc/build/changelog/unreleased_14/5979.rst
new file mode 100644
index 000000000..e9671409b
--- /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 763b4cabb..c4577e397 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 140de8622..9e818e997 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