Skip to content

Conversation

@sangeethailango
Copy link
Member

@sangeethailango sangeethailango commented Aug 22, 2025

Description

This PR will fix bugs related to search issues.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Summary by CodeRabbit

  • Bug Fixes
    • Issue search results now correctly exclude the current issue and its related issues when applicable, preventing self or related duplicates from appearing.
    • Exclusions are applied only when the referenced issue exists; otherwise, results remain unchanged.
    • Improves result relevance and reduces noise in issue searches.

@sangeethailango sangeethailango marked this pull request as ready for review August 22, 2025 11:07
@makeplane
Copy link

makeplane bot commented Aug 22, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

The issue search filter now appends the current issue’s ID to related issue IDs and performs a single exclusion of all those IDs when the issue exists. If the issue is not found, no exclusions are applied. No public interfaces or surrounding logic were changed.

Changes

Cohort / File(s) Summary
Search issue filtering
apps/api/plane/app/views/search/issue.py
Consolidated exclusion logic: appends issue_id to related IDs and uses a single exclude(pk__in=...) when the issue exists; no-op if not found. No signature changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant S as SearchIssuesView
  participant R as IssueRepository

  C->>S: Request issues with "exclude related to issue_id"
  S->>R: Fetch issue by issue_id
  alt Issue exists
    S->>R: Get related_issue_ids
    Note right of S: Append current issue_id to exclusion set
    S->>R: Query issues exclude pk in [related_issue_ids + issue_id]
    R-->>S: Filtered results
  else Issue not found
    S->>R: Query issues without exclusions
    R-->>S: Unfiltered results
  end
  S-->>C: Return issues
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge my nose through fields of IDs,
Hop!—the current one joins the breeze.
Related burrows, neatly skipped,
A single leap, exclusions clipped.
Carrots counted, queries clean—
A tidy trail, swift and keen. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ 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-search-issues

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 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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/api/plane/app/views/search/issue.py (1)

74-78: Bug: possible AttributeError when issue is None; also prefer parent_id over parent

if issue.parent: will raise when issue is None because it’s outside the if issue: guard. Nest the check and use parent_id to avoid an extra fetch.

-        if issue:
-            issues = issues.filter(~Q(pk=issue_id), parent__isnull=True)
-        if issue.parent:
-            issues = issues.filter(~Q(pk=issue.parent_id))
+        if issue:
+            issues = issues.filter(~Q(pk=issue_id), parent__isnull=True)
+            if issue.parent_id:
+                issues = issues.filter(~Q(pk=issue.parent_id))
🧹 Nitpick comments (4)
apps/api/plane/app/views/search/issue.py (4)

54-66: Guard related-issue query behind existence check; dedupe IDs; avoid None; use issue.pk for type fidelity

Currently, the related-issue query runs even when the issue doesn’t exist, potentially matching NULL relations and doing unnecessary work. Flattening may include None and duplicates, and issue_id is appended before verifying existence. Refactor to only compute when the issue is found, dedupe with a set, drop None, and use issue.pk to preserve DB field type.

-        issue = Issue.issue_objects.filter(pk=issue_id).first()
-        related_issue_ids = (
-            IssueRelation.objects.filter(Q(related_issue=issue) | Q(issue=issue))
-            .values_list("issue_id", "related_issue_id")
-            .distinct()
-        )
-
-        related_issue_ids = [item for sublist in related_issue_ids for item in sublist]
-        related_issue_ids.append(issue_id)
-
-        if issue:
-            issues = issues.exclude(pk__in=related_issue_ids)
+        issue = Issue.issue_objects.filter(pk=issue_id).first()
+        if issue:
+            pairs = (
+                IssueRelation.objects.filter(Q(related_issue=issue) | Q(issue=issue))
+                .values_list("issue_id", "related_issue_id")
+                .distinct()
+            )
+            related_issue_ids = {x for pair in pairs for x in pair if x is not None}
+            related_issue_ids.add(issue.pk)
+            issues = issues.exclude(pk__in=list(related_issue_ids))

41-45: Prefer exclude with ORs; use parent_id to avoid extra fetch and handle None cleanly

The current triple negation filter works, but exclude is clearer and using parent_id avoids fetching the parent object. Also, building the OR expression handles the case where parent_id is None without relying on ~Q(pk=None).

-        if issue:
-            issues = issues.filter(
-                ~Q(pk=issue_id), ~Q(pk=issue.parent_id), ~Q(parent_id=issue_id)
-            )
+        if issue:
+            excludes = Q(pk=issue_id) | Q(parent_id=issue_id)
+            if issue.parent_id:
+                excludes |= Q(pk=issue.parent_id)
+            issues = issues.exclude(excludes)

55-63: Alternative: DB-only exclusion without Python-side flattening

If the relation set can grow large, consider keeping this in the DB with a union subquery (supported on Postgres/Django). This avoids pulling IDs into Python and generating very long IN lists.

-        related_issue_ids = (
-            IssueRelation.objects.filter(Q(related_issue=issue) | Q(issue=issue))
-            .values_list("issue_id", "related_issue_id")
-            .distinct()
-        )
-        related_issue_ids = [item for sublist in related_issue_ids for item in sublist]
-        related_issue_ids.append(issue_id)
-        if issue:
-            issues = issues.exclude(pk__in=related_issue_ids)
+        if issue:
+            qs_issue_ids = IssueRelation.objects.filter(issue=issue).values_list("related_issue_id", flat=True)
+            qs_related_ids = IssueRelation.objects.filter(related_issue=issue).values_list("issue_id", flat=True)
+            # Union the two subqueries and exclude the current issue separately
+            issues = issues.exclude(pk__in=qs_issue_ids.union(qs_related_ids)).exclude(pk=issue.pk)

Note: Keep this only if your DB is Postgres (Django supports UNION on same-model QuerySets there).


105-167: Add regression tests for new exclusion behavior

Given the search and exclusion logic is subtle, please add tests that verify:

  • When issue_relation=true and the issue exists, results exclude: (a) the issue itself and (b) all its related issues.
  • When the issue does not exist, no exclusions are applied.
  • Duplicated relations (A↔B and B↔A) do not cause errors and do not affect results beyond exclusion.
  • Parent-related exclusions do not raise if the issue has no parent.

I can draft pytest tests targeting the view with factory-generated Issues and IssueRelations. Want me to push a test module?

📜 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 d3b2699 and 75d32f5.

📒 Files selected for processing (1)
  • apps/api/plane/app/views/search/issue.py (1 hunks)
⏰ 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)

@sriramveeraghanta sriramveeraghanta merged commit 6e5549c into preview Aug 22, 2025
6 of 8 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-search-issues branch August 22, 2025 18:58
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