I noticed three layered defects while raising test coverage to 100%; together they make enable_mentor_count a no-op (or a crash) for discussions.
Where
most_active_mentors.count_comments_per_user, the discussion branch at most_active_mentors.py:115-130, and discussions.get_discussions GraphQL query at discussions.py:25-50.
What is wrong
- GraphQL fetches no comment author data. The discussion query only requests
comments(first: 1) { nodes { createdAt } }, so each comment node has no user/author field.
- Production would AttributeError if it ever got past the guard.
most_active_mentors.py:118-122 does comment.user / comment.user.login / comment.submitted_at / comment.ready_for_review_at on what is actually a plain dict. Attribute access on dicts raises AttributeError.
- Self-reference in the ignore check. Even if the data were present,
most_active_mentors.py:117-119 passes comment.user as both issue_user AND comment_user to ignore_comment, which evaluates comment_user.login == issue_user.login and always returns True, so every comment gets skipped.
Why it has not been spotted
enable_mentor_count defaults to False, and the GraphQL query returns comments(first: 1) so len(discussion["comments"]["nodes"]) > 0 is rarely true in a way that would surface the crash.
What a proper fix needs
- Expand the GraphQL query to fetch comment authors (and the discussion author, for the ignore-self check) with proper pagination.
- Replace attribute access with dict access in the discussion branch of
count_comments_per_user.
- Thread the discussion author through as
issue_user instead of reusing comment.user.
- Add a real test that runs against a representative GraphQL discussion response and asserts non-empty
mentor_activity.
Why this is tracked separately
I bumped --cov-fail-under to 100 in a separate PR. To keep that PR scoped to coverage, I marked the dead block with # pragma: no cover and referenced this issue. Removing the pragma is part of the proper fix above.
I noticed three layered defects while raising test coverage to 100%; together they make
enable_mentor_counta no-op (or a crash) for discussions.Where
most_active_mentors.count_comments_per_user, the discussion branch atmost_active_mentors.py:115-130, anddiscussions.get_discussionsGraphQL query atdiscussions.py:25-50.What is wrong
comments(first: 1) { nodes { createdAt } }, so each comment node has nouser/authorfield.most_active_mentors.py:118-122doescomment.user/comment.user.login/comment.submitted_at/comment.ready_for_review_aton what is actually a plain dict. Attribute access on dicts raisesAttributeError.most_active_mentors.py:117-119passescomment.useras bothissue_userANDcomment_usertoignore_comment, which evaluatescomment_user.login == issue_user.loginand always returns True, so every comment gets skipped.Why it has not been spotted
enable_mentor_countdefaults to False, and the GraphQL query returnscomments(first: 1)solen(discussion["comments"]["nodes"]) > 0is rarely true in a way that would surface the crash.What a proper fix needs
count_comments_per_user.issue_userinstead of reusingcomment.user.mentor_activity.Why this is tracked separately
I bumped
--cov-fail-underto 100 in a separate PR. To keep that PR scoped to coverage, I marked the dead block with# pragma: no coverand referenced this issue. Removing the pragma is part of the proper fix above.