Skip to content

Commit

Permalink
Fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
wantsui committed Sep 27, 2024
1 parent 7043c4a commit 0ee1dd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ddtrace/contrib/internal/celery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def retrieve_task_id(context):
# Check if the id is in the headers, then check the body for it.
# If we don't check the id first, we could wrongly assume no task_id
# when the task_id is in the body.
if headers and 'id' in headers:
if headers and "id" in headers:
# Protocol Version 2 (default from Celery 4.0)
return headers.get("id")
elif body and 'id' in body:
elif body and "id" in body:
# Protocol Version 1
return body.get("id")
8 changes: 6 additions & 2 deletions tests/contrib/celery/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_task_id_from_protocol_v1_no_headers():
task_id = retrieve_task_id(context)
assert task_id == "dffcaec1-dd92-4a1a-b3ab-d6512f4beeb7"


def test_task_id_from_protocol_v1_with_headers():
# ensures a `task_id` is properly returned when Protocol v1 is used with headers.
# `context` is an example of an emitted Signal with Protocol v1
Expand All @@ -187,15 +188,16 @@ def test_task_id_from_protocol_v1_with_headers():
"routing_key": "celery",
"retry_policy": None,
"headers": {
"header1": 'value',
"header2": 'value',
"header1": "value",
"header2": "value",
},
"properties": {},
}

task_id = retrieve_task_id(context)
assert task_id == "dffcaec1-dd92-4a1a-b3ab-d6512f4beeb7"


def test_task_id_from_protocol_v2_no_body():
# ensures a `task_id` is properly returned when Protocol v2 is used.
# `context` is an example of an emitted Signal with Protocol v2
Expand Down Expand Up @@ -231,6 +233,7 @@ def test_task_id_from_protocol_v2_no_body():
task_id = retrieve_task_id(context)
assert task_id == "7e917b83-4018-431d-9832-73a28e1fb6c0"


def test_task_id_from_protocol_v2_with_body():
# ensures a `task_id` is properly returned when Protocol v2 is used.
# `context` is an example of an emitted Signal with Protocol v2
Expand Down Expand Up @@ -270,6 +273,7 @@ def test_task_id_from_protocol_v2_with_body():
task_id = retrieve_task_id(context)
assert task_id == "7e917b83-4018-431d-9832-73a28e1fb6c0"


def test_task_id_from_blank_context():
# if there is no context (thus missing headers and body),
# no task_id is returned
Expand Down

0 comments on commit 0ee1dd2

Please sign in to comment.