"""
+ zero = self._joinpoint_zero()
+ if zero is None:
+ raise sa_exc.InvalidRequestError(
+ "Can't use filter_by when the first entity '%s' of a query "
+ "is not a mapped class. Please use the filter method instead, "
+ "or change the order of the entities in the query"
+ % self._query_entity_zero()
+ )
+
clauses = [
- _entity_descriptor(self._joinpoint_zero(), key) == value
+ _entity_descriptor(zero, key) == value
for key, value in kwargs.items()
]
return self.filter(*clauses)
"AS users_name FROM users WHERE name='ed'",
)
+ def test_filter_by_non_entity(self):
+ s = create_session()
+ e = sa.func.count(123)
+ assert_raises_message(
+ sa_exc.InvalidRequestError,
+ r"Can't use filter_by when the first entity 'count\(:count_1\)' of"
+ " a query is not a mapped class. Please use the filter method "
+ "instead, or change the order of the entities in the query",
+ s.query(e).filter_by,
+ col=42,
+ )
+
class HasAnyTest(fixtures.DeclarativeMappedTest, AssertsCompiledSQL):
__dialect__ = "default"