fix: exclude soft-deleted profile assignees#8869
fix: exclude soft-deleted profile assignees#8869GLDRoger wants to merge 2 commits intomakeplane:previewfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdates WorkspaceUserProfileEndpoint to count project issue metrics using active Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a mismatch in user profile sidebar project counts by ensuring assigned-related aggregates only consider active IssueAssignee rows (excluding soft-deleted assignments), aligning sidebar counts with other profile views.
Changes:
- Update
WorkspaceUserProfileEndpointproject aggregates to filter throughIssueAssigneewithdeleted_at IS NULL. - Add
distinct=Trueto project issue count aggregations to prevent overcounting due to join multiplicity. - Add a regression contract test covering active vs soft-deleted historical assignments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/api/plane/app/views/workspace/user.py | Adjusts project-level profile aggregates to exclude soft-deleted assignee relations and avoid overcounting via distinct=True. |
| apps/api/plane/tests/contract/app/test_workspace_user_profile_app.py | Adds regression coverage to ensure sidebar assigned counts ignore soft-deleted IssueAssignee rows. |
| assert len(response.data["project_data"]) == 1 | ||
| assert response.data["project_data"][0]["assigned_issues"] == 1 | ||
| assert response.data["project_data"][0]["completed_issues"] == 0 | ||
| assert response.data["project_data"][0]["pending_issues"] == 0 |
There was a problem hiding this comment.
This test’s pending_issues expectation is likely not representative of real workspaces/projects. Issue.save() only assigns a default state if State rows exist for the project; ProjectFactory doesn’t seed DEFAULT_STATES, so active_issue.state stays NULL and pending_issues becomes 0. In the actual app flow, project creation seeds default states, so an active assigned issue would typically yield pending_issues == 1. Consider seeding the project’s states in the test (e.g., create the default backlog state for the project) and assert the corresponding pending_issues, or drop the pending_issues assertion to keep the regression focused on excluding soft-deleted assignees.
| assert response.data["project_data"][0]["pending_issues"] == 0 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/api/plane/tests/contract/app/test_workspace_user_profile_app.py (1)
13-73: Well-structured regression test.The test correctly:
- Creates the workspace/project membership hierarchy with appropriate roles
- Uses
IssueAssignee.all_objects.create()to create soft-deleted assignment records withdeleted_atset- Verifies that only the single active assignment is counted
One minor suggestion: consider also asserting
created_issuescount to ensure the visible filter works independently of the assignment filter. Sincecreate_usercreates all issues but isn't the profiled user,created_issuesshould be 0.💡 Optional: Add created_issues assertion
assert response.data["project_data"][0]["assigned_issues"] == 1 assert response.data["project_data"][0]["completed_issues"] == 0 assert response.data["project_data"][0]["pending_issues"] == 0 + assert response.data["project_data"][0]["created_issues"] == 0🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/api/plane/tests/contract/app/test_workspace_user_profile_app.py` around lines 13 - 73, Add an assertion to the test_workspace_user_profile_excludes_soft_deleted_assignments_from_project_counts function verifying that the profiled user has zero created issues: after the existing response checks, assert response.data["project_data"][0]["created_issues"] == 0 to ensure the created_issues filter is working independently of assignment filtering.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/api/plane/tests/contract/app/test_workspace_user_profile_app.py`:
- Around line 13-73: Add an assertion to the
test_workspace_user_profile_excludes_soft_deleted_assignments_from_project_counts
function verifying that the profiled user has zero created issues: after the
existing response checks, assert
response.data["project_data"][0]["created_issues"] == 0 to ensure the
created_issues filter is working independently of assignment filtering.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c5d42be8-6658-49b9-8d27-bae35c81ed79
📒 Files selected for processing (2)
apps/api/plane/app/views/workspace/user.pyapps/api/plane/tests/contract/app/test_workspace_user_profile_app.py
Summary
Fixes a profile-count mismatch where the project sidebar on a user profile could include stale soft-deleted assignee relations.
Closes #8868.
Problem
WorkspaceUserProfileEndpointwas aggregating project counts withproject_issue__assignees__in=[user_id].That could still count historical
IssueAssigneerows after the assignment had been soft-deleted, causing the sidebar/project breakdown to drift from the overview cards and assigned work-item list.Minimal reproduction
IssueAssigneerows are soft-deleted.1assigned work item3Fix
IssueAssigneerowsproject_issue__issue_assignee__deleted_at__isnull=Truedistinct=Trueon the profile project aggregations to avoid overcountingVerification
python3 -m py_compile apps/api/plane/app/views/workspace/user.py apps/api/plane/tests/contract/app/test_workspace_user_profile_app.pygit diff --checkI did not run the full Django test suite locally because this environment did not have the upstream repo's full database/runtime test setup bootstrapped.
Summary by CodeRabbit