Skip to content

Draft: Improve typing for github_user attributes on GraphQL nodes#5100

Draft
Tanishq-mellu wants to merge 1 commit into
OWASP:mainfrom
Tanishq-mellu:github-user-typing-clean
Draft

Draft: Improve typing for github_user attributes on GraphQL nodes#5100
Tanishq-mellu wants to merge 1 commit into
OWASP:mainfrom
Tanishq-mellu:github-user-typing-clean

Conversation

@Tanishq-mellu

Copy link
Copy Markdown
Contributor

Refs #5080

Summary

This draft PR improves type information for several GraphQL node classes by making the github_user attribute visible to mypy.

Several resolver methods access github_user, but the attribute is not declared on the corresponding Strawberry types, which results in attr-defined errors during static type checking.

Changes

  • Add TYPE_CHECKING imports for GitHubUser
  • Add github_user: GitHubUser | None annotations to:
    • AdminNode
    • MentorNode
    • AuthUserNode

Validation

  • Ran pre-commit run mypy --all-files
  • No mypy errors were reported

Feedback requested

I'd appreciate feedback on whether this is the preferred pattern for exposing internal model attributes on Strawberry GraphQL node types while improving static typing.

Question for reviewers

Is explicitly annotating model-backed attributes on Strawberry node types the preferred approach for resolving these attr-defined mypy errors, or would you recommend a different typing pattern?

Signed-off-by: Tanishq Meshram <tnshqmeshram@gmail.com>
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • issue_reference: This PR must be linked to an issue or include a valid closing issue reference in the description.

  • commit_signature: One or more commits are not signed.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added GitHub account details to user-related profiles in the app.
    • Admin, mentor, and authenticated user views can now show GitHub avatar, username, and display name when available.
    • When no GitHub account is linked, these fields appear empty instead of breaking the response.

Walkthrough

Three GraphQL node types (AdminNode, MentorNode, AuthUserNode) gain an optional github_user: GitHubUser | None field via TYPE_CHECKING imports. AdminNode additionally gains three resolver methods—avatar_url, login, and name—that read from github_user and return "" when it is None.

Changes

GitHubUser field on GraphQL nodes

Layer / File(s) Summary
github_user field and resolvers on AdminNode, MentorNode, AuthUserNode
backend/src/apps/mentorship/api/internal/nodes/admin.py, backend/src/apps/mentorship/api/internal/nodes/mentor.py, backend/src/apps/nest/api/internal/nodes/user.py
All three nodes add `github_user: GitHubUser

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving typing for github_user attributes on GraphQL nodes.
Description check ✅ Passed The description matches the changeset and explains the mypy typing fix for github_user on the GraphQL nodes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/apps/mentorship/api/internal/nodes/admin.py`:
- Around line 7-15: The AdminNode model is exposing an internal github_user
attribute as a public GraphQL field, and its TYPE_CHECKING-only annotation
causes a NameError at class definition time. Update AdminNode to keep the
backing GitHub user reference private by changing the github_user attribute to
Strawberry private storage using strawberry.Private with the GitHubUser | None
type, so the field is not part of the GraphQL schema and no runtime lookup of
GitHubUser is required.

In `@backend/src/apps/mentorship/api/internal/nodes/mentor.py`:
- Around line 7-15: The MentorNode class is referencing GitHubUser at runtime
even though it is only imported under TYPE_CHECKING, which causes the class body
to fail when evaluated. Update MentorNode to treat github_user as an
internal-only field by using a Strawberry private attribute, and keep the symbol
names MentorNode and github_user as the place to make the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bd14916c-b251-4d30-8a7e-0f0e9861cf9c

📥 Commits

Reviewing files that changed from the base of the PR and between 6feccc1 and 84314bf.

📒 Files selected for processing (3)
  • backend/src/apps/mentorship/api/internal/nodes/admin.py
  • backend/src/apps/mentorship/api/internal/nodes/mentor.py
  • backend/src/apps/nest/api/internal/nodes/user.py

Comment thread backend/src/apps/mentorship/api/internal/nodes/admin.py
Comment thread backend/src/apps/mentorship/api/internal/nodes/mentor.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 3 files

Confidence score: 2/5

  • In backend/src/apps/nest/api/internal/nodes/user.py and backend/src/apps/mentorship/api/internal/nodes/mentor.py, GitHubUser is only imported under TYPE_CHECKING but referenced in runtime-evaluated annotations, which can trigger NameError during import/schema resolution and break API startup—make the type available at runtime (or defer/quote the annotation) before merging.
  • In backend/src/apps/mentorship/api/internal/nodes/admin.py and backend/src/apps/mentorship/api/internal/nodes/mentor.py, github_user is currently treated as a public Strawberry field, so internal model data could leak into the GraphQL schema or cause type-mapping issues—mark it as a Strawberry private field (or otherwise exclude it from schema generation) before merging.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/src/apps/mentorship/api/internal/nodes/admin.py
Comment thread backend/src/apps/nest/api/internal/nodes/user.py
Comment thread backend/src/apps/mentorship/api/internal/nodes/mentor.py
Comment thread backend/src/apps/mentorship/api/internal/nodes/mentor.py
@Tanishq-mellu Tanishq-mellu marked this pull request as ready for review June 30, 2026 14:13
@Tanishq-mellu

Copy link
Copy Markdown
Contributor Author

Hi maintainers! Thanks for taking a look.

This is my first contribution to the typing improvements tracked in #5080, so I wanted to open it as a draft to validate the approach before making similar changes elsewhere.

The goal of this PR is only to resolve the attr-defined mypy errors by explicitly annotating the github_user attribute on the affected Strawberry node types. I intentionally kept the scope small so it's easier to review.

If this isn't the preferred pattern, I'd really appreciate guidance on the recommended approach. I'm happy to revise the implementation or explore an alternative solution based on your feedback.

Also, I noticed the automated review comments regarding runtime annotations and Strawberry private fields. I haven't addressed those yet because I'd first like to confirm the intended direction with the maintainers rather than making assumptions.
Thanks for your time and feedback

@arkid15r arkid15r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/OWASP/Nest/blob/main/CONTRIBUTING.md#contributing-workflow

Also make it holistic, if you fix a class of issues in the code I expect some pyproject.toml changes as well.

@arkid15r arkid15r marked this pull request as draft July 1, 2026 03:14
@Tanishq-mellu

Tanishq-mellu commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the clarification. I investigated the scope by temporarily removing the attr-defined suppression locally. That exposes 18 attr-defined errors across ProgramNode, ModuleNode and MilestoneQuery, many of which are related to Strawberry-Django model-backed nodes. I'll work on addressing the issue holistically and update the corresponding pyproject.toml configuration as part of the fix. If there's a preferred typing pattern for these Strawberry-Django nodes that you'd like me to follow, please let me know; otherwise I'll proceed with the approach that removes the need for the suppression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants