Skip to content

Exception thrown when instructor list results contain records without a profile  #31

@bermudezjd

Description

@bermudezjd

The sort_and_format_instructor_display method assumes that instructor result records will contain a profile key that is either null or a list. However, the rest api returns None records instead of nulls, so using default values with a get doesn't fall back to the default. This results in a 'NoneType' object has no attribute 'get' exception that looks like this (from Splunk logs):

Server Error: /course_info/lti_launch Traceback (most recent call last): File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner response = get_response(request) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response response = self._get_response(request) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view return view_func(request, *args, **kwargs) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/views/decorators/http.py", line 40, in inner return func(request, *args, **kwargs) File "/var/opt/virtualenvs/canvas_course_info/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) File "/opt/tlt/canvas_course_info/course_info/views.py", line 82, in lti_launch return editor(request) File "/opt/tlt/canvas_course_info/course_info/views.py", line 196, in editor course_instance_id=course_instance_id) File "/opt/tlt/canvas_course_info/course_info/views.py", line 142, in _course_context instructor_display = sort_and_format_instructor_display(course_instructor_list) File "/opt/tlt/canvas_course_info/course_info/views.py", line 211, in sort_and_format_instructor_display course_instructor_list.sort(key=lambda x: (x.get('role', {}).get('role_id'), File "/opt/tlt/canvas_course_info/course_info/views.py", line 213, in <lambda> x.get('profile', {}).get('name_last'))) AttributeError: 'NoneType' object has no attribute 'get'

Further checks may be needed in the code to handle cases where instructors don't have profiles, including adding checks to the get_display_name method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions