summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/attributes.py16
-rw-r--r--lib/sqlalchemy/sql/coercions.py2
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 9e326db64..0c7bc4cf0 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -46,6 +46,7 @@ from .base import RELATED_OBJECT_OK # noqa
from .base import SQL_OK # noqa
from .base import state_str
from .. import event
+from .. import exc
from .. import inspection
from .. import util
from ..sql import base as sql_base
@@ -229,7 +230,20 @@ class QueryableAttribute(
"entity_namespace": self._entity_namespace,
}
- return self.comparator.__clause_element__()._annotate(annotations)
+ ce = self.comparator.__clause_element__()
+ try:
+ anno = ce._annotate
+ except AttributeError as ae:
+ util.raise_(
+ exc.InvalidRequestError(
+ 'When interpreting attribute "%s" as a SQL expression, '
+ "expected __clause_element__() to return "
+ "a ClauseElement object, got: %r" % (self, ce)
+ ),
+ from_=ae,
+ )
+ else:
+ return anno(annotations)
@property
def _entity_namespace(self):
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index c00262fd5..b7aba9d74 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -313,7 +313,7 @@ class _ColumnCoercions(object):
def _implicit_coercions(
self, original_element, resolved, argname=None, **kw
):
- if not resolved.is_clause_element:
+ if not getattr(resolved, "is_clause_element", False):
self._raise_for_expected(original_element, argname, resolved)
elif resolved._is_select_statement:
self._warn_for_scalar_subquery_coercion()