Skip to content

Modify server_track to handle being called without a request. - #2076

Merged
brianhw merged 1 commit into
masterfrom
brian/server-track-null-request
Jan 6, 2014
Merged

Modify server_track to handle being called without a request.#2076
brianhw merged 1 commit into
masterfrom
brian/server-track-null-request

Conversation

@brianhw

@brianhw brianhw commented Jan 3, 2014

Copy link
Copy Markdown
Contributor

@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.

Comment thread common/djangoapps/track/views.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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'),
}

@brianhw

brianhw commented Jan 6, 2014

Copy link
Copy Markdown
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.)

@rocha

rocha commented Jan 6, 2014

Copy link
Copy Markdown
Contributor

LGTM 🚀

brianhw added a commit that referenced this pull request Jan 6, 2014
Modify server_track to handle being called without a request.
@brianhw
brianhw merged commit 9c81a07 into master Jan 6, 2014
@brianhw
brianhw deleted the brian/server-track-null-request branch January 6, 2014 15:15
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.
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