summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-10-15 18:13:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-10-15 18:13:33 -0400
commitaf3c8a75c8e9eba593f6568187226548f1b8735d (patch)
tree65d9477b4f132a90e7e2221c2ca086ad61744126
parente46836e6613906585546da5276b5f9bbe3254d79 (diff)
downloadsqlalchemy-af3c8a75c8e9eba593f6568187226548f1b8735d.tar.gz
- allow a __clause_element__() to be passed to query.filter() also
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/orm/query.py9
-rw-r--r--test/orm/test_query.py9
3 files changed, 12 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index c1f4ede43..da57c086a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -295,7 +295,8 @@ underneath "0.7.xx".
of "SomeClass.somerelationship" when used in a
core SQL context; previously, it would "resolve"
to the parent selectable, which wasn't generally
- useful. Related to [ticket:2245].
+ useful. Also works with query.filter().
+ Related to [ticket:2245].
- [feature] The registry of classes
in declarative_base() is now a
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index ca38d726c..35d32651f 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1187,14 +1187,7 @@ class Query(object):
"""
for criterion in list(criterion):
- if isinstance(criterion, basestring):
- criterion = sql.text(criterion)
-
- if criterion is not None and \
- not isinstance(criterion, sql.ClauseElement):
- raise sa_exc.ArgumentError(
- "filter() argument must be of type "
- "sqlalchemy.sql.ClauseElement or string")
+ criterion = expression._literal_as_text(criterion)
criterion = self._adapt_clause(criterion, True, True)
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 52f83ba32..11d86a5f0 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -1130,6 +1130,15 @@ class FilterTest(QueryTest, AssertsCompiledSQL):
#assert [User(id=7), User(id=9), User(id=10)] == sess.query(User).filter(User.addresses!=address).all()
+ def test_clause_element_ok(self):
+ User = self.classes.User
+ s = Session()
+ self.assert_compile(
+ s.query(User).filter(User.addresses),
+ "SELECT users.id AS users_id, users.name AS users_name "
+ "FROM users, addresses WHERE users.id = addresses.user_id"
+ )
+
def test_unique_binds_join_cond(self):
"""test that binds used when the lazyclause is used in criterion are unique"""