Bläddra i källkod

Joining in task now raises RuntimeError instead of warning

Ask Solem 9 år sedan
förälder
incheckning
b27856df0e
2 ändrade filer med 10 tillägg och 4 borttagningar
  1. 1 4
      celery/result.py
  2. 9 0
      celery/tests/tasks/test_result.py

+ 1 - 4
celery/result.py

@@ -33,15 +33,12 @@ E_WOULDBLOCK = """\
 Never call result.get() within a task!
 See http://docs.celeryq.org/en/latest/userguide/tasks.html\
 #task-synchronous-subtasks
-
-In Celery 4.0 this will result in an exception being
-raised instead of just being a warning.
 """
 
 
 def assert_will_not_block():
     if task_join_will_block():
-        warnings.warn(RuntimeWarning(E_WOULDBLOCK))
+        raise RuntimeError(E_WOULDBLOCK)
 
 
 @contextmanager

+ 9 - 0
celery/tests/tasks/test_result.py

@@ -9,6 +9,7 @@ from celery.result import (
     AsyncResult,
     EagerResult,
     result_from_tuple,
+    assert_will_not_block,
 )
 from celery.utils import uuid
 from celery.utils.serialization import pickle
@@ -57,6 +58,14 @@ class test_AsyncResult(AppCase):
             pass
         self.mytask = mytask
 
+    @patch('celery.result.task_join_will_block')
+    def test_assert_will_not_block(self, task_join_will_block):
+        task_join_will_block.return_value = True
+        with self.assertRaises(RuntimeError):
+            assert_will_not_block()
+        task_join_will_block.return_value = False
+        assert_will_not_block()
+
     def test_compat_properties(self):
         x = self.app.AsyncResult('1')
         self.assertEqual(x.task_id, x.id)