From 0ca7b53b4235c2fbabfbb6a4e2df2f7a369df6f2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 12 Jul 2013 11:32:34 -0400 Subject: Fixed bug where the expression system relied upon the ``str()`` form of a some expressions when referring to the ``.c`` collection on a ``select()`` construct, but the ``str()`` form isn't available since the element relies on dialect-specific compilation constructs, notably the ``__getitem__()`` operator as used with a Postgresql ``ARRAY`` element. The fix also adds a new exception class :class:`.UnsupportedCompilationError` which is raised in those cases where a compiler is asked to compile something it doesn't know how to. Also in 0.8.3. [ticket:2780] --- test/sql/test_compiler.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/sql/test_compiler.py') diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 8b9f9cfa4..bdfcccb22 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2482,6 +2482,46 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) +class UnsupportedTest(fixtures.TestBase): + def test_unsupported_element_str_visit_name(self): + from sqlalchemy.sql.expression import ClauseElement + class SomeElement(ClauseElement): + __visit_name__ = 'some_element' + + assert_raises_message( + exc.UnsupportedCompilationError, + r"Compiler ", + SomeElement().compile + ) + + def test_unsupported_element_meth_visit_name(self): + from sqlalchemy.sql.expression import ClauseElement + class SomeElement(ClauseElement): + @classmethod + def __visit_name__(cls): + return "some_element" + + assert_raises_message( + exc.UnsupportedCompilationError, + r"Compiler ", + SomeElement().compile + ) + + def test_unsupported_operator(self): + from sqlalchemy.sql.expression import BinaryExpression + def myop(x, y): + pass + binary = BinaryExpression(column("foo"), column("bar"), myop) + assert_raises_message( + exc.UnsupportedCompilationError, + r"Compiler