Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom headers propagation for protocol 1 hybrid messages #6374

Merged
merged 1 commit into from Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"