Explorar el Código

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 hace 9 años
padre
commit
144dd4b4e6
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  1. 4 0
      celery/result.py

+ 4 - 0
celery/result.py

@@ -778,6 +778,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