Skip to content

Bug Report: Missing null checks for credit_service in api.py #1311

@dinosv

Description

@dinosv

Summary

Two locations in edx_proctoring/api.py call methods on credit_service without checking if it's None, causing crashes when the credit service is
not available. This is common in Tutor deployments that don't have credit eligibility enabled.

Affected Code

Location 1: Line ~1648 in update_attempt_status()

# call service to get course name.
credit_service = get_runtime_service('credit')
credit_state = credit_service.get_credit_state(  # <-- crashes if credit_service is None
    exam_attempt_obj.user_id,
    exam_attempt_obj.proctored_exam.course_id,
    return_course_info=True
)

Error:

AttributeError: 'NoneType' object has no attribute 'get_credit_state'

Location 2: Line ~1517 in update_attempt_status()

credit_service = get_runtime_service('credit')
# ... status logic ...
credit_service.set_credit_requirement_status(  # <-- crashes if credit_service is None
    user_id=exam_attempt_obj.user_id,
    course_key_or_id=exam['course_id'],
    req_namespace='proctored_exam',
    req_name=exam_attempt_obj.proctored_exam.content_id,
    status=credit_requirement_status
)

Error:

AttributeError: 'NoneType' object has no attribute 'set_credit_requirement_status'

Suggested Fix

Location 1:

credit_service = get_runtime_service('credit')
if credit_service:
    credit_state = credit_service.get_credit_state(
        exam_attempt_obj.user_id,
        exam_attempt_obj.proctored_exam.course_id,
        return_course_info=True
    )
else:
    credit_state = None

Location 2:

if credit_service:
    credit_service.set_credit_requirement_status(
        user_id=exam_attempt_obj.user_id,
        course_key_or_id=exam['course_id'],
        req_namespace='proctored_exam',
        req_name=exam_attempt_obj.proctored_exam.content_id,
        status=credit_requirement_status
    )

Environment

  • Tutor version: 21.0.0
  • Open edX release: Sumac
  • edx-proctoring: Installed via OPENEDX_EXTRA_PIP_REQUIREMENTS
  • Exam type: Timed exams (non-proctored)
  • Proctoring backend: null

Steps to Reproduce

  1. Deploy Open edX using Tutor 21
  2. Install edx-proctoring via OPENEDX_EXTRA_PIP_REQUIREMENTS
  3. Enable timed exams with the null proctoring backend
  4. Do NOT enable ENABLE_CREDIT_ELIGIBILITY or configure the credit service
  5. Create a timed exam in Studio
  6. As a student, attempt to start or submit the timed exam
  7. Observe the 500 error

Impact

Students cannot start or submit timed exams when the credit service is not configured, even though credit functionality is not needed for basic timed
exams.

Notes

Other parts of the codebase already follow the pattern of checking if credit_service: before calling methods. These two locations appear to have bee
n missed.

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