summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/visitors.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-07-12 11:32:34 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-07-12 11:32:34 -0400
commit0ca7b53b4235c2fbabfbb6a4e2df2f7a369df6f2 (patch)
tree7afb656369eb8a2e49621a012003bd28f8c0d0e5 /lib/sqlalchemy/sql/visitors.py
parent269a166b73a84914b8601b3a714d682ef7eb87f5 (diff)
downloadsqlalchemy-0ca7b53b4235c2fbabfbb6a4e2df2f7a369df6f2.tar.gz
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]
Diffstat (limited to 'lib/sqlalchemy/sql/visitors.py')
-rw-r--r--lib/sqlalchemy/sql/visitors.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py
index 24ada8d9f..7b729bf7f 100644
--- a/lib/sqlalchemy/sql/visitors.py
+++ b/lib/sqlalchemy/sql/visitors.py
@@ -26,6 +26,7 @@ http://techspot.zzzeek.org/2008/01/23/expression-transformations/
from collections import deque
from .. import util
import operator
+from .. import exc
__all__ = ['VisitableType', 'Visitable', 'ClauseVisitor',
'CloningVisitor', 'ReplacingCloningVisitor', 'iterate',
@@ -70,14 +71,24 @@ def _generate_dispatch(cls):
getter = operator.attrgetter("visit_%s" % visit_name)
def _compiler_dispatch(self, visitor, **kw):
- return getter(visitor)(self, **kw)
+ try:
+ meth = getter(visitor)
+ except AttributeError:
+ raise exc.UnsupportedCompilationError(visitor, cls)
+ else:
+ return meth(self, **kw)
else:
# The optimization opportunity is lost for this case because the
# __visit_name__ is not yet a string. As a result, the visit
# string has to be recalculated with each compilation.
def _compiler_dispatch(self, visitor, **kw):
visit_attr = 'visit_%s' % self.__visit_name__
- return getattr(visitor, visit_attr)(self, **kw)
+ try:
+ meth = getattr(visitor, visit_attr)
+ except AttributeError:
+ raise exc.UnsupportedCompilationError(visitor, cls)
+ else:
+ return meth(self, **kw)
_compiler_dispatch.__doc__ = \
"""Look for an attribute named "visit_" + self.__visit_name__