case here is fairly experimental, but only
adds one line of code to Query.
+ - [bug] the @compiles decorator raises an
+ informative error message when no "default"
+ compilation handler is present, rather
+ than KeyError.
+
- examples
- [bug] Fixed bug in history_meta.py example where
the "unique" flag was not removed from a
)
"""
+from sqlalchemy import exc
def compiles(class_, *specs):
def decorate(fn):
# TODO: yes, this could also switch off of DBAPI in use.
fn = self.specs.get(compiler.dialect.name, None)
if not fn:
- fn = self.specs['default']
+ try:
+ fn = self.specs['default']
+ except KeyError:
+ raise exc.CompileError(
+ "%s construct has no default "
+ "compilation handler." % type(element))
return fn(element, compiler, **kw)
from sqlalchemy.schema import DDLElement
from sqlalchemy.ext.compiler import compiles
+from sqlalchemy import exc
from sqlalchemy.sql import table, column, visitors
+from test.lib.testing import assert_raises_message
from test.lib import *
class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL):
"FROM mytable WHERE mytable.x > :x_1)"
)
+ def test_no_default_message(self):
+ class MyThingy(ColumnClause):
+ pass
+
+ @compiles(MyThingy, "psotgresql")
+ def visit_thingy(thingy, compiler, **kw):
+ return "mythingy"
+
+ assert_raises_message(
+ exc.CompileError,
+ "<class 'test.ext.test_compiler.MyThingy'> "
+ "construct has no default compilation handler.",
+ str, MyThingy('x')
+ )
+
def test_annotations(self):
"""test that annotated clause constructs use the
decorated class' compiler.