Skip to content

Commit

Permalink
Fix custom headers propagation for protocol 1 hybrid messages
Browse files Browse the repository at this point in the history
  • Loading branch information
beezz authored and auvipy committed Sep 30, 2020
1 parent cd8782f commit 0f1a53b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions celery/worker/strategy.py
Expand Up @@ -50,6 +50,7 @@ def hybrid_to_proto2(message, body):
'kwargsrepr': body.get('kwargsrepr'),
'origin': body.get('origin'),
}
headers.update(message.headers or {})

embed = {
'callbacks': body.get('callbacks'),
Expand Down
4 changes: 2 additions & 2 deletions t/unit/worker/test_request.py
Expand Up @@ -1204,8 +1204,8 @@ def test_execute_using_pool_with_none_timelimit_header(self):

def test_execute_using_pool__defaults_of_hybrid_to_proto2(self):
weakref_ref = Mock(name='weakref.ref')
headers = strategy.hybrid_to_proto2('', {'id': uuid(),
'task': self.mytask.name})[1]
headers = strategy.hybrid_to_proto2(Mock(headers=None), {'id': uuid(),
'task': self.mytask.name})[1]
job = self.zRequest(revoked_tasks=set(), ref=weakref_ref, **headers)
job.execute_using_pool(self.pool)
assert job._apply_result
Expand Down
6 changes: 5 additions & 1 deletion t/unit/worker/test_strategy.py
Expand Up @@ -271,7 +271,7 @@ def failed():
class test_hybrid_to_proto2:

def setup(self):
self.message = Mock(name='message')
self.message = Mock(name='message', headers={"custom": "header"})
self.body = {
'args': (1,),
'kwargs': {'foo': 'baz'},
Expand All @@ -288,3 +288,7 @@ def test_retries_custom_value(self):
self.body['retries'] = _custom_value
_, headers, _, _ = hybrid_to_proto2(self.message, self.body)
assert headers.get('retries') == _custom_value

def test_custom_headers(self):
_, headers, _, _ = hybrid_to_proto2(self.message, self.body)
assert headers.get("custom") == "header"

0 comments on commit 0f1a53b

Please sign in to comment.