Skip to content

feat: return detailed error from proctoring provider - #38925

Open
Anas12091101 wants to merge 3 commits into
openedx:masterfrom
mitodl:anas/return-detail-proctoring-error
Open

feat: return detailed error from proctoring provider#38925
Anas12091101 wants to merge 3 commits into
openedx:masterfrom
mitodl:anas/return-detail-proctoring-error

Conversation

@Anas12091101

@Anas12091101 Anas12091101 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Description

Resetting a proctored exam attempt from the new instructor dashboard previously failed with a generic 500 when the proctoring provider was slow/unavailable, leaving the attempt "stuck" with no explanation.

This PR updates the Instructor v2 reset endpoint (SpecialExamResetView in lms/djangoapps/instructor/views/api_v2.py) to catch ProctoredBaseException from remove_exam_attempt and return the exception's own status + message:

except ProctoredBaseException as err:
    return Response({'detail': str(err)}, status=err.http_status)

Now a provider failure returns a 502 with a clear detail (e.g. "The proctoring provider is temporarily unavailable… please try again in a few minutes."), which the instructor-dashboard MFE already displays. Same pattern as the existing ProctoredBaseException handling in this file.

Impacted roles: Instructor/Course Staff (clear error instead of a 500), Operator (failure is now logged/typed).

Supporting information

  • Bug: instructor dashboard "reset exam attempt error" (reset 500s, attempt remains) with the Proctortrack provider.
  • Depends on openedx/edx-proctoring#1337, which raises the typed BackendProviderCannotRemoveAttempt (502) this view relies on.
  • Screenshot
Screenshot 2026-07-28 at 1 15 00 PM

Testing instructions

Automated:

pytest lms/djangoapps/instructor/tests/views/test_special_exams_api_v2.py::SpecialExamResetViewTest

Manual (needs edx-proctoring >= 6.1.0):

  1. Create a proctored exam (REST backend) and have a learner start an attempt.
  2. Make the provider fail — point the backend base_url at an unreachable host (or stub remove_exam_attempt to raise).
  3. As instructor, reset the attempt (dashboard → Special Exams → Exam Attempts).
  4. Expect: 502 with {"detail": "…temporarily unavailable…"}, the message shown in the UI, attempt still present, error logged.
  5. Regression: with a healthy provider, reset still returns 200 and removes the attempt.

Deadline

None, though it fixes a production-visible bug.

Other information

@openedx-webhooks

openedx-webhooks commented Jul 27, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Anas12091101!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jul 27, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Jul 27, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jul 27, 2026
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions Aug 20, 2026
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Aug 20, 2026
@Anas12091101
Anas12091101 force-pushed the anas/return-detail-proctoring-error branch from 246c2b6 to ddefbac Compare August 31, 2026 13:48
@AhtishamShahid

Copy link
Copy Markdown
Contributor

Tested this together with openedx/edx-proctoring#1337 (proctoring package overlaid into
the LMS image, real chain: view → api.remove_exam_attemptdelete_exam_attempt
pre_delete → backend). The core fix works: provider down now returns 502 with the
message instead of a 500, the attempt is preserved, and a healthy provider still resets
normally. Two things worth a look before merge.

1. detail vs error key

The new branch returns {'detail': ...}, but every other error branch in this same view
returns {'error': ...} ("User not found", "Exam not found", "No attempts found").
detail is the DRF convention, so this may well be right — but could you confirm the
instructor-dashboard MFE reads detail here? If it reads error, the instructor sees a
blank/generic message and the fix is invisible. Returning both keys would be a cheap
hedge.

2. Learner with 2+ attempts: reset gets permanently stuck

get_user_attempts_by_exam_id returns all of a learner's attempts and the loop removes
each one. If the provider fails partway, the already-succeeded provider-side deletes are
not rolled back, but ATOMIC_REQUESTS (True in production) rolls back all the local
deletes. Local and provider state then diverge, and every retry re-attempts the
already-deleted attempt upstream, where the provider 404s — which #1337 turns into a
raise. Result: 502 forever, the exam can never be reset.

Repro (needs #1337 installed; two attempts on one exam, provider fails on the second call):

@patch('edx_proctoring.handlers.get_backend_provider')
def test_partial_failure(self, get_backend_mock):
    calls = []

    def flaky(exam_ext, attempt_ext):
        calls.append(attempt_ext)
        if len(calls) == 2:
            raise ConnectionError('provider down')
        return True

    get_backend_mock.return_value.remove_exam_attempt.side_effect = flaky
    response = self.client.post(self._url())

    print(response.status_code, calls)
    print(list(ProctoredExamStudentAttempt.objects
               .filter(user=self.student).values_list('external_id', flat=True)))

What I get:

502  ['ext-a2', 'ext-a1']      # a2 deleted upstream, a1 failed
['ext-a1', 'ext-a2']           # both still present locally — rolled back

Re-posting the same reset three times: 502 / 502 / 502, 2 attempts left every time.

Note that moving the try/except inside the loop does not fix this — the raise from
the pre_delete signal marks the connection needs-rollback, so the next query throws
TransactionManagementError. That suggests the real fix belongs in #1337: call the
provider before delete_exam_attempt() and branch on the result, rather than raising
from a pre_delete signal. If that changes there, this PR stays correct as written.

Otherwise this looks good — small, matches the existing ProctoredBaseException handling
in this file, and ProctoredBaseException.http_status defaults to 400 so err.http_status
can't blow up.

Addresses review feedback: the instructor-dashboard MFE reads `detail` (DRF
convention), while the other error branches in this view use `error`. Return the
message under both so it is surfaced regardless of which key the consumer reads.
@Anas12091101

Copy link
Copy Markdown
Contributor Author

Thanks @AhtishamShahid for the detailed review. I have updated openedx/edx-proctoring#1337 to match your suggestions. Could you please take another look?

@AhtishamShahid AhtishamShahid self-assigned this Sep 2, 2026
@AhtishamShahid AhtishamShahid removed the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants