Skip to content

Update strawberry_django decorators#3404

Merged
arkid15r merged 4 commits intoOWASP:feature/e2e-backendfrom
ahmedxgouda:e2e/prefetch-related
Jan 18, 2026
Merged

Update strawberry_django decorators#3404
arkid15r merged 4 commits intoOWASP:feature/e2e-backendfrom
ahmedxgouda:e2e/prefetch-related

Conversation

@ahmedxgouda
Copy link
Collaborator

Proposed change

Resolves #(put the issue number here)

Add the PR description here.

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Recent issues queries now support filtering by author login and repository organization
    • Added distinct parameter to recent issues queries
    • Member snapshots endpoint updated with pagination support via limit parameter
  • Chores

    • Refined internal GraphQL resolver configurations across multiple endpoints for improved query handling

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR removes select_related and prefetch_related optimizations from multiple GraphQL query and node field decorators across GitHub and OWASP backend modules, while selectively adding select_related hints to five UserNode fields. It also introduces a GenericRelation to RepositoryBasedEntityModel and refactors entity_leaders logic to use this relation.

Changes

Cohort / File(s) Summary
GitHub GraphQL Query Decorators (optimization removal)
backend/apps/github/api/internal/queries/issue.py, milestone.py, pull_request.py, release.py, repository.py, user.py
Removed select_related and prefetch_related parameters from @strawberry_django.field decorators on recent_issues, recent_milestones, recent_pull_requests, recent_releases, repositories, and user field resolvers. Issue query additionally introduces distinct, limit, login, and organization parameters with corresponding filter logic.
OWASP GraphQL Query Decorators (optimization removal)
backend/apps/owasp/api/internal/queries/chapter.py, project.py, snapshot.py
Removed select_related and prefetch_related parameters from field decorators on recent_chapters, recent_projects, search_projects, and snapshots resolvers.
OWASP member_snapshot Query
backend/apps/owasp/api/internal/queries/member_snapshot.py
Removed decorator optimization hints and significantly refactored member_snapshots resolver: changed from single-object filtering by github_user/start_at to list-based filtering by user_login with limit capping and start_at descending ordering; removed start_year parameter support.
OWASP Model & Node Refactor
backend/apps/owasp/models/common.py, backend/apps/owasp/api/internal/nodes/common.py
Added GenericRelation field entity_members to RepositoryBasedEntityModel; refactored entity_leaders method to use the new relation instead of manual ContentType-based filtering. Added prefetch_related=["entity_members__member"] to entity_leaders field decorator.
GitHub UserNode Field Optimizations
backend/apps/github/api/internal/nodes/user.py
Added select_related=["owasp_profile"] to field decorators on first_owasp_contribution_at, is_owasp_board_member, is_former_owasp_staff, is_gsoc_mentor, and linkedin_page_id resolvers; streamlined return logic from explicit conditionals to inline conditionals.
Test Update
backend/tests/apps/owasp/api/internal/nodes/common_test.py
Changed entity_leaders invocation from class method call to instance method call (GenericEntityNode().entity_leaders(mock_entity)).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • kasya
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description contains only the repository's PR template with placeholders ('put the issue number here', 'Add the PR description here') and provides no substantive details about the actual changes made to the codebase. Replace the template placeholders with specific details about the decorator changes, affected files, migration rationale, and any performance or behavioral implications of removing/adding prefetch_related and select_related optimizations.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Update strawberry_django decorators' directly describes the main change across the changeset—simplifying and updating decorator configurations on multiple GraphQL field resolvers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions
Copy link

PR validation failed: No linked issue and no valid closing issue reference in PR description

@github-actions github-actions bot closed this Jan 18, 2026
@ahmedxgouda ahmedxgouda reopened this Jan 18, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/tests/apps/owasp/api/internal/nodes/common_test.py`:
- Around line 16-24: The test incorrectly expects the resolver
GenericEntityNode.entity_leaders to call
mock_entity.entity_leaders.order_by("order"), but the resolver simply returns
root.entity_leaders (ordering is handled by the model property). Update the test
to stop asserting order_by was called: remove or replace
mock_entity.entity_leaders.order_by.assert_called_once_with("order") and instead
assert the resolver returned the mock_entity.entity_leaders value (e.g., keep
result == [mock_leader1, mock_leader2] or set mock_entity.entity_leaders to the
ordered list before calling GenericEntityNode.entity_leaders).
🧹 Nitpick comments (2)
backend/apps/owasp/api/internal/queries/member_snapshot.py (1)

64-67: Avoid the extra lookup query for user_login.

You can filter by the related login directly to avoid the User.objects.get round‑trip and exception handling.

♻️ Proposed refactor
-        if user_login:
-            try:
-                snapshots = snapshots.filter(github_user=User.objects.get(login=user_login))
-            except User.DoesNotExist:
-                return []
+        if user_login:
+            snapshots = snapshots.filter(github_user__login=user_login)
backend/apps/owasp/models/common.py (1)

101-104: Minor: Return type annotation mismatch.

The property returns a QuerySet, not a list[EntityMember]. While this works in practice since QuerySets are iterable, consider updating the annotation for accuracy:

♻️ Suggested type annotation fix
+from django.db.models import QuerySet
+
 `@cached_property`
-def entity_leaders(self) -> list[EntityMember]:
+def entity_leaders(self) -> QuerySet[EntityMember]:
     """Return entity's leaders."""
     return self.entity_members.filter(role=EntityMember.Role.LEADER).order_by("order")

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 18, 2026
@ahmedxgouda ahmedxgouda marked this pull request as ready for review January 18, 2026 12:32
@sonarqubecloud
Copy link

@arkid15r arkid15r enabled auto-merge (squash) January 18, 2026 19:48
@arkid15r arkid15r disabled auto-merge January 18, 2026 22:09
@arkid15r arkid15r merged commit 711a5f1 into OWASP:feature/e2e-backend Jan 18, 2026
28 of 30 checks passed
arkid15r added a commit that referenced this pull request Jan 19, 2026
* Update strawberry_django decorators

* Update entity_leaders

* Update tests

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
arkid15r added a commit that referenced this pull request Jan 19, 2026
* Update strawberry_django decorators

* Update entity_leaders

* Update tests

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
@ahmedxgouda ahmedxgouda deleted the e2e/prefetch-related branch January 19, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments