Commits

Mike Bayer committed 29f608d

- [bug] Fixed bug in relationship comparisons
whereby calling unimplemented methods like
SomeClass.somerelationship.like() would
produce a recursion overflow, instead
of NotImplementedError.

Comments (0)

Files changed (4)

     OrderingList from being pickleable
     [ticket:2454].  Courtesy Jeff Dairiki
 
+  - [bug] Fixed bug in relationship comparisons
+    whereby calling unimplemented methods like
+    SomeClass.somerelationship.like() would
+    produce a recursion overflow, instead
+    of NotImplementedError.
+
 - sql
   - [bug] Removed warning when Index is created
     with no columns; while this might not be what 

lib/sqlalchemy/orm/properties.py

             else:
                 return elem
 
-        def operate(self, op, *other, **kwargs):
-            return op(self, *other, **kwargs)
-
-        def reverse_operate(self, op, other, **kwargs):
-            return op(self, *other, **kwargs)
-
         def of_type(self, cls):
             """Produce a construct that represents a particular 'subtype' of
             attribute for the parent class.

lib/sqlalchemy/sql/operators.py

     return a.like(b, escape=escape)
 
 def notlike_op(a, b, escape=None):
-    raise NotImplementedError()
+    return ~a.like(b, escape=escape)
 
 def ilike_op(a, b, escape=None):
     return a.ilike(b, escape=escape)
 
 def notilike_op(a, b, escape=None):
-    raise NotImplementedError()
+    return ~a.ilike(b, escape=escape)
 
 def between_op(a, b, c):
     return a.between(b, c)
     return a.in_(b)
 
 def notin_op(a, b):
-    raise NotImplementedError()
+    return ~a.in_(b)
 
 def distinct_op(a):
     return a.distinct()

test/orm/test_query.py

         self._test(None == Address.user, "addresses.user_id IS NULL")
         self._test(~(None == Address.user), "addresses.user_id IS NOT NULL")
 
+    def test_relationship_unimplemented(self):
+        User, Address = self.classes.User, self.classes.Address
+        for op in [
+            User.addresses.like,
+            User.addresses.ilike,
+            User.addresses.__le__,
+            User.addresses.__gt__,
+        ]:
+            assert_raises(NotImplementedError, op, "x")
+
     def test_relationship(self):
         User, Address = self.classes.User, self.classes.Address