Page MenuHomePhabricator

Fix server error when coordinators view their own application to a resource they don't coordinate that has no coordinator
Closed, ResolvedPublic

Description

Over the weekend one the Wikipedia Library's coordinators applied for access to a resource (one they aren't the coordinator for). They received a server error when attempting to view their application.

Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/app/TWLight/view_mixins.py", line 317, in dispatch
    return super(NotDeleted, self).dispatch(request, *args, **kwargs)
  File "/app/TWLight/view_mixins.py", line 165, in dispatch
    if not test_func_partner_coordinator_or_self(self.get_object(), request.user):
  File "/app/TWLight/view_mixins.py", line 149, in test_func_partner_coordinator_or_self
    return test_func_partner_coordinator(obj, user) or test_func_self_only(obj, user)
  File "/app/TWLight/view_mixins.py", line 83, in test_func_partner_coordinator
    obj_partner_coordinator_test = obj.partner.coordinator.pk == user.pk

Exception Type: AttributeError at /applications/evaluate/12013/
Exception Value: 'NoneType' object has no attribute 'pk'

This likely happened because we're using test_func_partner_coordinator_or_self. That function returns test_func_partner_coordinator(obj, user) or test_func_self_only(obj, user). test_func_partner_coordinator first checks the coordinator of the resource. If there is no coordinator, it will error.

Event Timeline

We could either update test_func_partner_coordinator to return None if the partner has no coordinator instead of erroring, or reorganise test_func_partner_coordinator_or_self so it checks self first.

I have raised a pull request for this at https://github.com/WikipediaLibrary/TWLight/pull/577 And I have tested it manually it is working fine now.

jsn.sherman subscribed.

Merged. Thanks!