Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/djangoapps/track/views/segmentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements

# Start with the context provided by Segment in the "client" field if it exists
# We should tightly control which fields actually get included in the event emitted.
segment_context = full_segment_event.get('context', {})
segment_context = full_segment_event.get('context') or {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original line uses the DICT.get('KEY', {}) pattern to look up a value in a dictionary, falling back to an empty dictionary if the key is missing. The issue with this approach is that if KEY is present in DICT, but has a value of None, then the result will be None instead of {}.

My proposed change is to use DICT.get('KEY') or {}, which will return {} whether KEY is missing or present with a None value.

There are several other places in this function (such as line 126 above) that use the old pattern. Should I change those too?


# Build up the event context by parsing fields out of the event received from Segment
context = {}
Expand Down