Modify server_track to handle being called without a request. - #2076
Merged
Conversation
Contributor
There was a problem hiding this comment.
why not simply: agent = request.META.get('HTTP_USER_AGENT', '')?
I tend to try to avoid bare except clauses if at all possible.
Maybe something like:
def get_request_header(request, header_name):
if request is None or not hasattr(request, 'META') or header_name not in request.META:
return ''
else:
return request.META[header_name]
event = {
"ip": get_request_header(request, 'REMOTE_ADDR'),
"host": get_request_header(request, 'SERVER_NAME'),
}
Contributor
Author
|
Updated based on feedback from @mulby. (I had been too timid about request.META before, fearing that it was a QueryDict like POST and GET and might generate other errors. But META is just a dict, so we shouldn't need to use try/except to access META parameters.) |
Contributor
|
LGTM 🚀 |
brianhw
added a commit
that referenced
this pull request
Jan 6, 2014
Modify server_track to handle being called without a request.
shimulch
pushed a commit
to open-craft/openedx-platform
that referenced
this pull request
Jan 26, 2021
…K-1890-japanese YONK-1890 | Added missing translation for Japanese language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@rocha @mulby Here's a more minimalistic fix for AN-361. I'm splitting off the changes to add tracking context from a command into a separate PR, since that part is not required to be able to run create_user, and seems to engender more discussion.