diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-02-26 15:25:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-02-26 15:25:19 +0000 |
| commit | a8678d660af78a93e08585540e7a23e0b4229ff1 (patch) | |
| tree | 8b14ed5119291b8f93cf0795c1c5c3717702640e | |
| parent | fca7bda9eb39b3130b87aca025ab56374b7179e3 (diff) | |
| parent | 6cd195c4a1589620784b052a041e691427d1e086 (diff) | |
| download | sqlalchemy-a8678d660af78a93e08585540e7a23e0b4229ff1.tar.gz | |
Merge "implement visit_unsupported_compilation for TypeCompiler"
| -rw-r--r-- | doc/build/changelog/unreleased_14/5979.rst | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 6 | ||||
| -rw-r--r-- | test/sql/test_compiler.py | 14 |
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 |
