Browse Source

apply_async: Raise ValueError if task args is not a list, or kwargs is not a tuple. Closes #95. Thanks to TheAtilla.

Ask Solem 15 years ago
parent
commit
ad8443eb2c
2 changed files with 15 additions and 0 deletions
  1. 7 0
      celery/messaging.py
  2. 8 0
      celery/tests/test_task.py

+ 7 - 0
celery/messaging.py

@@ -57,6 +57,13 @@ class TaskPublisher(Publisher):
         if countdown: # Convert countdown to ETA.
             eta = datetime.now() + timedelta(seconds=countdown)
 
+        task_args = task_args or []
+        task_kwargs = task_kwargs or {}
+        if not isinstance(task_args, (list, tuple)):
+            raise ValueError("task args must be a list or tuple")
+        if not isinstance(task_kwargs, dict):
+            raise ValueError("task kwargs must be a dictionary")
+
         message_data = {
             "task": task_name,
             "id": task_id,

+ 8 - 0
celery/tests/test_task.py

@@ -261,6 +261,14 @@ class TestCeleryTasks(unittest.TestCase):
 
         self.assertRaises(NotImplementedError, IncompleteTask().run)
 
+    def test_task_kwargs_must_be_dictionary(self):
+        self.assertRaises(ValueError, IncrementCounterTask.apply_async,
+                          [], "str")
+
+    def test_task_args_must_be_list(self):
+        self.assertRaises(ValueError, IncrementCounterTask.apply_async,
+                          "str", {})
+
     def test_regular_task(self):
         T1 = self.createTaskCls("T1", "c.unittest.t.t1")
         self.assertIsInstance(T1(), T1)