]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
filter() checks for ClauseElement [ticket:535]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 17 Jun 2007 01:06:00 +0000 (01:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 17 Jun 2007 01:06:00 +0000 (01:06 +0000)
lib/sqlalchemy/orm/query.py
test/orm/query.py

index a7bf73b80a33e50cb1a6c41cfa8b045419147fb9..0eea06e841a5a8f44cb1e2433a893287e6cad297 100644 (file)
@@ -243,6 +243,10 @@ class Query(object):
         
         the criterion is any sql.ClauseElement applicable to the WHERE clause of a select.
         """
+        
+        if not isinstance(criterion, sql.ClauseElement):
+            raise exceptions.ArgumentError("filter() argument must be of type sqlalchemy.sql.ClauseElement")
+            
         q = self._clone()
         if q._criterion is not None:
             q._criterion = q._criterion & criterion
@@ -256,7 +260,7 @@ class Query(object):
         import properties
         
         if len(args) > 1:
-            raise exceptions.InvalidRequestError("filter_by() takes either zero positional arguments, or one scalar or list argument indicating a property search path.")
+            raise exceptions.ArgumentError("filter_by() takes either zero positional arguments, or one scalar or list argument indicating a property search path.")
         if len(args) == 1:
             path = args[0]
             (join, joinpoint, alias) = self._join_to(path, outerjoin=False, start=self.mapper, create_aliases=True)
index 6b77224e8519ede09d3783c24284db475e1392b5..2194565a14382aa71f779f52ed9ddbcdffdaf0bf 100644 (file)
@@ -158,6 +158,13 @@ class FilterTest(QueryTest):
     def test_onefilter(self):
         assert [User(id=8), User(id=9)] == create_session().query(User).filter(users.c.name.endswith('ed')).all()
 
+    def test_typecheck(self):
+        try:
+            create_session().query(User).filter(User.name==5)
+            assert False
+        except exceptions.ArgumentError, e:
+            assert str(e) == "filter() argument must be of type sqlalchemy.sql.ClauseElement"
+        
 class ParentTest(QueryTest):
     def test_o2m(self):
         sess = create_session()