Skip to content

Conversation

@sangeethailango
Copy link
Member

@sangeethailango sangeethailango commented Sep 2, 2025

Description

This PR will resolve the issue where only selected assignees, modules, and labels are displayed on the work items list during filtering.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • Bug Fixes

    • Corrected assignee, label, and module data in grouped issue views to prevent missing or duplicate entries.
    • Excludes deleted links and respects archived modules for more accurate results.
    • Improves consistency of filters and counts across issue lists.
  • Performance

    • Faster loading and smoother interaction when grouping or filtering issues, especially in large projects.
    • Reduces backend overhead for more responsive issue queries.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Reworked issue queryset annotations in apps/api/plane/utils/grouper.py to use Subquery/OuterRef for assignee_ids, label_ids, and module_ids with Coalesce defaults. Updated imports accordingly. Replaced prior ArrayAgg-based defaults with an explicit loop that skips fields used for group_by or sub_group_by.

Changes

Cohort / File(s) Summary
Query annotation refactor
apps/api/plane/utils/grouper.py
Added OuterRef/Subquery imports and IssueAssignee/ModuleIssue/IssueLabel models. Introduced three subqueries to aggregate related IDs. Replaced tuple-based and ArrayAgg annotations with Coalesce-wrapped subqueries and an explicit default annotations builder that omits current group_by/sub_group_by fields.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Grouper as issue_queryset_grouper
  participant ORM as Django ORM
  participant DB as Database

  Client->>Grouper: Request grouped issues
  Grouper->>ORM: Build QuerySet with Subquery/OuterRef annotations
  ORM->>DB: Execute main query + subqueries (assignees, labels, modules)
  DB-->>ORM: Result rows with annotated arrays (Coalesce defaults)
  ORM-->>Grouper: Annotated QuerySet
  Grouper-->>Client: Grouped issues response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

🐛bug

Poem

Thump-thump, I hop through fields of IDs,
Gathering assignees, labels, and modules with ease.
Subqueries bloom where ArrayAgg once grew,
Coalesce cushions when results are few.
In tidy rows my carrots align—
Grouped and annotated, crisp and fine.
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-assignee-icon-on-filter

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sangeethailango sangeethailango changed the title fix: work item filter [WEB-4129] fix: work item filter Sep 2, 2025
@makeplane
Copy link

makeplane bot commented Sep 2, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

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: 3

🧹 Nitpick comments (2)
apps/api/plane/utils/grouper.py (2)

51-51: Deterministic array ordering (optional).

If consumers compare arrays or serialize them for tests, add ordering to ArrayAgg to keep results stable.

-        .annotate(arr=ArrayAgg("assignee_id", distinct=True))
+        .annotate(arr=ArrayAgg("assignee_id", distinct=True, ordering=("assignee_id",)))
-        .annotate(arr=ArrayAgg("module_id", distinct=True))
+        .annotate(arr=ArrayAgg("module_id", distinct=True, ordering=("module_id",)))
-        .annotate(arr=ArrayAgg("label_id", distinct=True))
+        .annotate(arr=ArrayAgg("label_id", distinct=True, ordering=("label_id",)))

Also applies to: 63-63, 69-69


73-83: Fix the typing of annotations_map.

The values are Django expressions, not Tuple[str, Q]. This misleads type checkers.

-    annotations_map: Dict[str, Tuple[str, Q]] = {
+    annotations_map: Dict[str, Any] = {

Optional: DRY the empty array literal with a local constant to reduce repetition.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2d31b56 and be57d7f.

📒 Files selected for processing (1)
  • apps/api/plane/utils/grouper.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/api/plane/utils/grouper.py (2)
apps/api/plane/db/models/issue.py (2)
  • IssueAssignee (347-372)
  • IssueLabel (532-547)
apps/api/plane/db/models/module.py (1)
  • ModuleIssue (154-177)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/api/plane/utils/grouper.py (4)

4-4: LGTM on ORM imports.

Adding OuterRef/Subquery is appropriate for decoupling the aggregations from GROUP BY joins.


17-19: Model imports look correct.

Directly referencing IssueAssignee/ModuleIssue/IssueLabel avoids brittle reverse-name paths.


36-39: Align module archived filter between grouping and annotations.

You exclude archived modules in module_ids, but not when grouping by issue_module__module_id. This can surface archived groups that won’t appear in module_ids, causing inconsistent UI.

-        "issue_module__module_id": Q(issue_module__deleted_at__isnull=True),
+        "issue_module__module_id": Q(
+            issue_module__deleted_at__isnull=True,
+            issue_module__module__archived_at__isnull=True,
+        ),

Confirm whether archived modules should be excluded from grouping; if not, drop the archived filter from the subquery instead for consistency.


85-91: Be defensive about group_by keys format.

If upstream ever passes "assignee_ids" instead of "assignees__id", the skip won’t trigger. Guard for both.

-        if FIELD_MAPPER.get(key) in {group_by, sub_group_by}:
+        if FIELD_MAPPER.get(key) in {group_by, sub_group_by} or key in {group_by, sub_group_by}:
             continue

Please confirm the canonical values of group_by/sub_group_by across callers.

@sriramveeraghanta sriramveeraghanta merged commit 2e67302 into preview Sep 3, 2025
7 of 10 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-assignee-icon-on-filter branch September 3, 2025 13:06
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.

4 participants