Browse Source

Adding the __bool__ and __nonzero__ methods to GroupResult

This is to fix an issue where a ResultSet or GroupResult with an empty
result list are not properly tupled with the as_tuple() method when it is
a parent result. This is due to the as_tuple() method performing a logical
and operation on the ResultSet.
Colin McIntosh 9 years ago
parent
commit
255459d3a8
1 changed files with 4 additions and 0 deletions
  1. 4 0
      celery/result.py

+ 4 - 0
celery/result.py

@@ -851,6 +851,10 @@ class GroupResult(ResultSet):
     def __reduce_args__(self):
         return self.id, self.results
 
+    def __bool__(self):
+        return bool(self.id or self.results)
+    __nonzero__ = __bool__  # Included for Py2 backwards compatibility
+
     def __eq__(self, other):
         if isinstance(other, GroupResult):
             return other.id == self.id and other.results == self.results