Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise errors with expected format #11541

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

bjester
Copy link
Member

@bjester bjester commented Nov 17, 2023

Summary

  • Updates get_remote_users_info to raise errors with expected format to avoid 500 errors

Screenshot from 2023-11-17 07-46-36

References

#11540 - does not entirely fix, as there is no error handling (?)

Prior error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/core/tasks/api.py", line 198, in create
    validated_data = self.validate_create_req_data(request)
  File "/usr/lib/python3/dist-packages/kolibri/core/tasks/api.py", line 68, in validate_create_req_data
    job, enqueue_args = registered_task.validate_job_data(
  File "/usr/lib/python3/dist-packages/kolibri/core/tasks/registry.py", line 272, in validate_job_data
    validator.is_valid(raise_exception=True)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/serializers.py", line 236, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "/usr/lib/python3/dist-packages/kolibri/core/tasks/validation.py", line 123, in run_validation
    value = self.validate(value)
  File "/usr/lib/python3/dist-packages/kolibri/core/auth/tasks.py", line 535, in validate
    facility_info = get_remote_users_info(baseurl, facility_id, username, password)
  File "/usr/lib/python3/dist-packages/kolibri/core/auth/utils/users.py", line 57, in get_remote_users_info
    raise AuthenticationFailed(detail)
rest_framework.exceptions.AuthenticationFailed: [{'id': ErrorDetail(string='AUTHENTICATION_FAILED', code='authentication_failed'), 'message': ErrorDetail(string='401 Client Error: Unauthorized for url: http://192.168.100.49:8080/api/public/facilityuser/?facility_id=13785e243c00fb2b8b0a70b0f2ce0ffe', code='authentication_failed')}]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/viewsets.py", line 116, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/usr/lib/python3/dist-packages/kolibri/dist/rest_framework/views.py", line 452, in handle_exception
    response = exception_handler(exc, context)
  File "/usr/lib/python3/dist-packages/kolibri/core/utils/exception_handler.py", line 21, in custom_exception_handler
    response.data = _handle_403_format(response, context)
  File "/usr/lib/python3/dist-packages/kolibri/core/utils/exception_handler.py", line 60, in _handle_403_format
    "id": response.data["detail"].code.upper(),
TypeError: list indices must be integers or slices, not str

Reviewer guidance

Provide incorrect credentials when attempting to import a single learner in the setup wizard


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... SIZE: small labels Nov 17, 2023
@bjester bjester added the TODO: needs review Waiting for review label Nov 17, 2023
@bjester bjester marked this pull request as ready for review November 17, 2023 15:53
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Would be nice if we could lint for this kind of thing - but I've never got my head around how to make custom Python linting rules.

@bjester bjester merged commit f6e02e4 into learningequality:release-v0.16.x Nov 17, 2023
35 checks passed
@nick2432 nick2432 mentioned this pull request Jan 6, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem... SIZE: small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants