]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- allow a __clause_element__() to be passed to query.filter() also
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Oct 2012 22:13:33 +0000 (18:13 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Oct 2012 22:13:33 +0000 (18:13 -0400)
CHANGES
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

diff --git a/CHANGES b/CHANGES
index c1f4ede430a02c02241bfa3f1d1a8971ac085525..da57c086a9580414ccd1aca65a1e5d3bffd325dd 100644 (file)
--- 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
index ca38d726cffc61f4f39f39bb0f082c1991e2b328..35d32651fdb9bfd13c19a89f8c380bc37cd45a4e 100644 (file)
@@ -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)
 
index 52f83ba32bc8be2bf116b55cac40f3cc7da0340d..11d86a5f0f4cf1be58fec0bd99f69ea67f9f0d49 100644 (file)
@@ -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"""