summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-06-29 11:11:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-29 11:14:28 -0400
commitacd8b1c107d536669ca7200edbca0f039f1e79fb (patch)
tree8b18ab41e44dc4f5c80f11229b9d28a1f6a9f999 /lib/sqlalchemy/ext/compiler.py
parent7c74d702a9632a8c7264d6972e46985de3fb2487 (diff)
downloadsqlalchemy-acd8b1c107d536669ca7200edbca0f039f1e79fb.tar.gz
Ensure @compiles calls down to the original compilation scheme
Made a slight behavioral change in the ``sqlalchemy.ext.compiler`` extension, whereby the existing compilation schemes for an established construct would be removed if that construct was itself didn't already have its own dedicated ``__visit_name__``. This was a rare occurrence in 1.0, however in 1.1 :class:`.postgresql.ARRAY` subclasses :class:`.sqltypes.ARRAY` and has this behavior. As a result, setting up a compilation handler for another dialect such as SQLite would render the main :class:`.postgresql.ARRAY` object no longer compilable. Fixes: #3732 Change-Id: If2c1ada4eeb09157885888e41f529173902f2b49
Diffstat (limited to 'lib/sqlalchemy/ext/compiler.py')
-rw-r--r--lib/sqlalchemy/ext/compiler.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py
index 86156be1f..5ef4e1d2a 100644
--- a/lib/sqlalchemy/ext/compiler.py
+++ b/lib/sqlalchemy/ext/compiler.py
@@ -410,13 +410,25 @@ def compiles(class_, *specs):
given :class:`.ClauseElement` type."""
def decorate(fn):
+ # get an existing @compiles handler
existing = class_.__dict__.get('_compiler_dispatcher', None)
- existing_dispatch = class_.__dict__.get('_compiler_dispatch')
+
+ # get the original handler. All ClauseElement classes have one
+ # of these, but some TypeEngine classes will not.
+ existing_dispatch = getattr(class_, '_compiler_dispatch', None)
+
if not existing:
existing = _dispatcher()
if existing_dispatch:
- existing.specs['default'] = existing_dispatch
+ def _wrap_existing_dispatch(element, compiler, **kw):
+ try:
+ return existing_dispatch(element, compiler, **kw)
+ except exc.UnsupportedCompilationError:
+ raise exc.CompileError(
+ "%s construct has no default "
+ "compilation handler." % type(element))
+ existing.specs['default'] = _wrap_existing_dispatch
# TODO: why is the lambda needed ?
setattr(class_, '_compiler_dispatch',
@@ -458,4 +470,5 @@ class _dispatcher(object):
raise exc.CompileError(
"%s construct has no default "
"compilation handler." % type(element))
+
return fn(element, compiler, **kw)