diff --git a/owl/course.py b/owl/course.py
index 6fe5cb83958b2ebe49f068e3c0589c8192d03bc0..b22c2512ab0b11f5559a094d3bcb234fbc19ddf9 100644
--- a/owl/course.py
+++ b/owl/course.py
@@ -223,11 +223,18 @@ def topic_index(sident: str, cident: str, tident: str, student_uid: Optional[int
     if student_uid is not None:
         if not g.is_grader:
             raise werkzeug.exceptions.Forbidden('Only graders are allowed to do that')
+        enroll = sess.scalar(
+            select(db.Enroll)
+            .filter_by(uid=student_uid, cid=g.course.cid, is_teacher=False)
+            .options(joinedload(db.Enroll.user))
+        )
+        if enroll is None:
+            raise werkzeug.exceptions.NotFound('No such student of this course')
         if g.course.anon_grading and not g.is_teacher:
             show_for_user = f'Student {student_uid}'
             filename_base = str(student_uid)
         else:
-            show_for_user = sess.get(db.User, student_uid).full_name()
+            show_for_user = enroll.user.full_name()
             filename_base = show_for_user
     else:
         show_for_user = None