Skip to content

Discussion mentor counting is dead code (GraphQL + ignore_comment self-reference + dict-vs-object mismatch) #774

Description

@zkoppert

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

  1. 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.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalebugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions