--- /dev/null
+.. change::
+ :tags: bug, ext, associationproxy
+ :tickets: 5541, 5542
+
+ It's not possible right now to use an association proxy element as a plain
+ column expression to be SELECTed from or used in a SQL function. An
+ informative error is now raised when this occurs.
+
def _comparator(self):
return self._get_property().comparator
+ def __clause_element__(self):
+ raise NotImplementedError(
+ "The association proxy can't be used as a plain column "
+ "expression; it only works inside of a comparison expression"
+ )
+
@classmethod
def _cls_unwrap_target_assoc_proxy(cls, target_class, value_attr):
attr = getattr(target_class, value_attr)
from sqlalchemy import cast
from sqlalchemy import exc
from sqlalchemy import ForeignKey
+from sqlalchemy import func
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
eq_(str(proxy_sql), str(direct_sql))
eq_(q_proxy.all(), q_direct.all())
+ def test_no_straight_expr(self):
+ User = self.classes.User
+
+ assert_raises_message(
+ NotImplementedError,
+ "The association proxy can't be used as a plain column expression",
+ func.foo,
+ User.singular_value,
+ )
+
+ assert_raises_message(
+ NotImplementedError,
+ "The association proxy can't be used as a plain column expression",
+ self.session.query,
+ User.singular_value,
+ )
+
def test_filter_any_criterion_ul_scalar(self):
UserKeyword, User = self.classes.UserKeyword, self.classes.User