Skip to content

Conversation

@kdmccormick
Copy link
Member

@kdmccormick kdmccormick commented Sep 17, 2020

Should resolve the AttributeError on the line:

   library_name = segment_context.get('library', ...

that occurs when full_segment_event['context'] == None.

This error is currently the #1 in LMS and is obscuring other errors.


I think this was the cause of the alert this morning; my NewRelic-fu isn't developed enough to be sure though.

I don't know whether this is the right fix. Maybe it's good to have that AttributeError yelling at us until we can find out why we are getting segment events with None as their context. I'm posting in hope of soliciting feedback.

What do you think @stvstnfrd ?


Update: This can't be the cause of the alert this morning, because it's owned by platform-data-de, and we still see the error spike even when filtering that DE's endpoints out of the query.

Should resolve the AttributeError on the line
   library_name = segment_context.get('library', ...
that occurs when full_segment_event['context'] == None.

This error is currently the #1 in LMS and is obscuring other
errors.
@kdmccormick kdmccormick force-pushed the kdmccormick/segment-content-none branch from e6c40fe to 98232f1 Compare September 17, 2020 13:22
# 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?

@kdmccormick kdmccormick marked this pull request as draft September 17, 2020 13:28
@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@kdmccormick
Copy link
Member Author

This error does not seem to be occurring any more; closing.

@kdmccormick kdmccormick closed this Oct 9, 2020
@kdmccormick kdmccormick deleted the kdmccormick/segment-content-none branch October 9, 2020 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants