Browse Source

make missing args/kwargs in protocol v1 message to return empty value in protocol v2 message (#3695)

Roman Sichny 8 years ago
parent
commit
5a87ede8b2
2 changed files with 5 additions and 5 deletions
  1. 1 1
      celery/worker/strategy.py
  2. 4 4
      t/unit/worker/test_strategy.py

+ 1 - 1
celery/worker/strategy.py

@@ -30,7 +30,7 @@ def proto1_to_proto2(message, body):
         Tuple: of ``(body, headers, already_decoded_status, utc)``
     """
     try:
-        args, kwargs = body['args'], body['kwargs']
+        args, kwargs = body.get('args', ()), body.get('kwargs', {})
         kwargs.items  # pylint: disable=pointless-statement
     except KeyError:
         raise InvalidTaskError('Message does not have args/kwargs')

+ 4 - 4
t/unit/worker/test_strategy.py

@@ -27,13 +27,13 @@ class test_proto1_to_proto2:
 
     def test_message_without_args(self):
         self.body.pop('args')
-        with pytest.raises(InvalidTaskError):
-            proto1_to_proto2(self.message, self.body)
+        body, _, _, _ = proto1_to_proto2(self.message, self.body)
+        assert body[:2] == ((), {'foo': 'baz'})
 
     def test_message_without_kwargs(self):
         self.body.pop('kwargs')
-        with pytest.raises(InvalidTaskError):
-            proto1_to_proto2(self.message, self.body)
+        body, _, _, _ = proto1_to_proto2(self.message, self.body)
+        assert body[:2] == ((1,), {})
 
     def test_message_kwargs_not_mapping(self):
         self.body['kwargs'] = (2,)