def get_all_submissions(course_id, item_id, item_type, read_replica=True):
submission_qs = Submission.objects<EOL>if read_replica:<EOL><INDENT>submission_qs = _use_read_replica(submission_qs)<EOL><DEDENT>query = submission_qs.select_related('<STR_LIT>').filter(<EOL>student_item__course_id=course_id,<EOL>student_item__item_id=item_id,<EOL>student_item__item_type=item_type,<EOL>).order_by('<STR_LIT>', '<STR_LIT>', '<STR_LIT>').iterator()<EOL>for unused_student_id, row_iter in itertools.groupby(query, operator.attrgetter('<STR_LIT>')):<EOL><INDENT>submission = next(row_iter)<EOL>data = SubmissionSerializer(submission).data<EOL>data['<STR_LIT>'] = submission.student_item.student_id<EOL>yield data<EOL><DEDENT>
For the given item, get the most recent submission for every student who has submitted.

    This may return a very large result set! It is implemented as a generator for efficiency.

    Args:
        course_id, item_id, item_type (string): The values of the respective student_item fields
            to filter the submissions by.
        read_replica (bool): If true, attempt to use the read replica database.
            If no read replica is available, use the default database.

    Yields:
        Dicts representing the submissions with the following fields:
            student_item
            student_id
            attempt_number
            submitted_at
            created_at
            answer

    Raises:
        Cannot fail unless there's a database error, but may return an empty iterable.