From: Mike Bayer Date: Mon, 15 Oct 2012 22:13:33 +0000 (-0400) Subject: - allow a __clause_element__() to be passed to query.filter() also X-Git-Tag: rel_0_8_0b1~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af3c8a75c8e9eba593f6568187226548f1b8735d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - allow a __clause_element__() to be passed to query.filter() also --- diff --git a/CHANGES b/CHANGES index c1f4ede430..da57c086a9 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 ca38d726cf..35d32651fd 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 52f83ba32b..11d86a5f0f 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"""