Skip to content

fix: filter out soft-deleted states from API endpoints#8840

Open
KanteshMurade wants to merge 2 commits intomakeplane:previewfrom
KanteshMurade:preview
Open

fix: filter out soft-deleted states from API endpoints#8840
KanteshMurade wants to merge 2 commits intomakeplane:previewfrom
KanteshMurade:preview

Conversation

@KanteshMurade
Copy link
Copy Markdown

@KanteshMurade KanteshMurade commented Mar 31, 2026

Fixes #8829 (via issue endpoint filtering)

Problem

Soft-deleted states were reappearing in the UI after navigation.

Although states were correctly soft-deleted in the database (deleted_at set), API responses were still returning them, causing the frontend to repopulate deleted states.

Root Cause

The issue was initially suspected in the state API endpoints. However, State.objects already excludes soft-deleted records via the SoftDeletionManager.

The actual root cause was that issues referencing soft-deleted states were still being returned in the issue API responses.

Solution

  • Removed redundant .filter(deleted_at__isnull=True) from state endpoints
  • Added filtering in issue queryset:
    state__deleted_at__isnull=True
  • Ensured the serializer uses the filtered queryset (issue_queryset) for consistency

Endpoint Clarification

Although the issue mentions state endpoints, the fix is applied in issue endpoints because they return state data indirectly through issue relationships.

Scope

This change intentionally updates the issue endpoint (IssueListEndpoint) to ensure soft-deleted states are excluded from all API responses.

Type of Change

  • Bug fix

Test Scenarios

  • Create a state
  • Delete the state (soft delete)
  • Navigate away and return to the same page
  • Verify the deleted state does NOT reappear

Screenshots

N/A

Result

  • Soft-deleted states no longer reappear in the UI
  • API responses are consistent and accurate

- Add deleted_at__isnull=True filter to StateListCreateAPIEndpoint.get_queryset()
- Add deleted_at__isnull=True filter to StateDetailAPIEndpoint.get_queryset()
- Prevents soft-deleted states from reappearing in UI after navigation
- Fixes makeplane#8829
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The IssueListEndpoint.get method now filters out soft-deleted states from the issues queryset by adding a state__deleted_at__isnull=True constraint. When fields or expansion is requested, the serializer now uses the fully filtered queryset instead of the base queryset to ensure consistency.

Changes

Cohort / File(s) Summary
Issue List Filtering
apps/api/plane/app/views/issue/base.py
Added state__deleted_at__isnull=True filter to exclude soft-deleted states from issues queryset. Updated serializer input to use the filtered issue_queryset when self.fields or self.expand is specified, ensuring serialized results align with the filtered queryset.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A state once soft-deleted, now fades away,
No ghost-states haunting the light of day,
The queryset filters with gentle care,
Deleted states vanish into thin air! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR description and changes address the core requirement from issue #8829 to filter soft-deleted states, but the actual code changes in the raw_summary show modifications to IssueListEndpoint rather than StateListCreateAPIEndpoint or StateDetailAPIEndpoint as described. Clarify whether changes were made to the correct endpoints (StateListCreateAPIEndpoint and StateDetailAPIEndpoint) as specified in issue #8829, or if the scope has expanded to issue-related filtering.
Out of Scope Changes check ⚠️ Warning The raw_summary shows modifications to IssueListEndpoint.get filtering soft-deleted states, which was not mentioned in the PR description that focuses only on State endpoints, indicating potential scope creep or undocumented changes. Either document the changes to IssueListEndpoint in the PR description or remove out-of-scope modifications to keep changes aligned with the stated objectives.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: filtering out soft-deleted states from API endpoints, which directly aligns with the changeset's objective.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering problem statement, root cause analysis, solution, scope, and test scenarios.

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

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 31, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/api/plane/api/views/state.py`:
- Line 57: The added .filter(deleted_at__isnull=True) calls are redundant
because State.objects uses StateManager which inherits SoftDeletionManager and
already applies that condition in get_queryset(); remove the explicit
.filter(deleted_at__isnull=True) occurrences (the ones added around the query
using State.objects) to avoid no-op duplication, and instead audit other query
paths that may bypass State.objects (e.g., direct State._default_manager, raw
queries, or explicit QuerySet.from_model calls) if deleted records are still
appearing; search for usages of .filter(deleted_at__isnull=True) in this module
and delete the redundant filters, keeping queries built with State.objects so
the manager-level soft-delete behavior remains authoritative.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 77490cbc-7d73-48f7-962c-24d724abca94

📥 Commits

Reviewing files that changed from the base of the PR and between a18d90d and 7b88af4.

📒 Files selected for processing (1)
  • apps/api/plane/api/views/state.py

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@KanteshMurade
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@KanteshMurade
Copy link
Copy Markdown
Author

Updated PR description and clarified scope. Ready for review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Soft-deleted states returned by workspace and project state endpoints, causing deleted states to reappear in UI

2 participants