def _get_or_create_student_item(student_item_dict):
try:<EOL><INDENT>try:<EOL><INDENT>return StudentItem.objects.get(**student_item_dict)<EOL><DEDENT>except StudentItem.DoesNotExist:<EOL><INDENT>student_item_serializer = StudentItemSerializer(<EOL>data=student_item_dict<EOL>)<EOL>if not student_item_serializer.is_valid():<EOL><INDENT>logger.error(<EOL>u"<STR_LIT>".format(<EOL>student_item_serializer.errors,<EOL>student_item_dict<EOL>)<EOL>)<EOL>raise SubmissionRequestError(field_errors=student_item_serializer.errors)<EOL><DEDENT>return student_item_serializer.save()<EOL><DEDENT><DEDENT>except DatabaseError:<EOL><INDENT>error_message = u"<STR_LIT>".format(<EOL>student_item_dict<EOL>)<EOL>logger.exception(error_message)<EOL>raise SubmissionInternalError(error_message)<EOL><DEDENT>
Gets or creates a Student Item that matches the values specified.

    Attempts to get the specified Student Item. If it does not exist, the
    specified parameters are validated, and a new Student Item is created.

    Args:
        student_item_dict (dict): The dict containing the student_id, item_id,
            course_id, and item_type that uniquely defines a student item.

    Returns:
        StudentItem: The student item that was retrieved or created.

    Raises:
        SubmissionInternalError: Thrown if there was an internal error while
            attempting to create or retrieve the specified student item.
        SubmissionRequestError: Thrown if the given student item parameters fail
            validation.

    Examples:
        >>> student_item_dict = dict(
        >>>    student_id="Tim",
        >>>    item_id="item_1",
        >>>    course_id="course_1",
        >>>    item_type="type_one"
        >>> )
        >>> _get_or_create_student_item(student_item_dict)
        {'item_id': 'item_1', 'item_type': 'type_one', 'course_id': 'course_1', 'student_id': 'Tim'}