diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php
index be536a5642c..5febc847778 100644
--- a/mod/quiz/report/overview/report.php
+++ b/mod/quiz/report/overview/report.php
@@ -420,7 +420,6 @@ class quiz_overview_report extends attempts_report {
      */
     protected function get_new_question_for_regrade(stdClass $attempt,
             question_usage_by_activity $quba, int $slot): question_definition {
-        global $DB;
 
         // If the cache is empty, get information about all the slots.
         if ($this->structureforregrade === null) {
@@ -430,14 +429,17 @@ class quiz_overview_report extends attempts_report {
                     $attempt->quiz, $this->context);
         }
 
+        // Because of 'Redo question in attempt' feature, we need to find the original slot number.
+        $originalslot = $quba->get_question_attempt_metadata($slot, 'originalslot') ?? $slot;
+
         // If this is a non-random slot, we will have the right info cached.
-        if ($this->structureforregrade[$slot]->qtype != 'random') {
+        if ($this->structureforregrade[$originalslot]->qtype != 'random') {
             // This is a non-random slot.
-            return question_bank::load_question($this->structureforregrade[$slot]->questionid);
+            return question_bank::load_question($this->structureforregrade[$originalslot]->questionid);
         }
 
         // We must be dealing with a random question. Check that cache.
-        $currentquestion = $quba->get_question_attempt($slot)->get_question(false);
+        $currentquestion = $quba->get_question_attempt($originalslot)->get_question(false);
         if (isset($this->newquestionidsforold[$currentquestion->id])) {
             return question_bank::load_question($this->newquestionidsforold[$currentquestion->id]);
         }
diff --git a/mod/quiz/tests/behat/attempt_redo_questions.feature b/mod/quiz/tests/behat/attempt_redo_questions.feature
index 1279eda0eff..58e8e950eca 100644
--- a/mod/quiz/tests/behat/attempt_redo_questions.feature
+++ b/mod/quiz/tests/behat/attempt_redo_questions.feature
@@ -43,6 +43,19 @@ Feature: Allow students to redo questions in a practice quiz, without starting a
     Then the state of "First question" question is shown as "Not complete"
     And I should see "Marked out of 2.00" in the "First question" "question"
 
+  @javascript
+  Scenario: After redoing a question, regrade works
+    Given I am on the "Quiz 1" "mod_quiz > View" page logged in as "student"
+    When I press "Attempt quiz"
+    And I click on "False" "radio" in the "First question" "question"
+    And I click on "Check" "button" in the "First question" "question"
+    And I press "Try another question like this one"
+    And I am on the "Quiz 1" "mod_quiz > Grades report" page logged in as "teacher"
+    And I press "Regrade all"
+    Then I should see "Finished regrading (1/1)"
+    And I should see "Regrade completed"
+    And I press "Continue"
+
   @javascript
   Scenario: Start attempt, teacher edits question, redo picks up latest non-draft version
     # Start attempt as student.