[GIT-229] fix: bucket cycle/module analytics chart by Issue.created_at - #9532
[GIT-229] fix: bucket cycle/module analytics chart by Issue.created_at#9532blockgroot wants to merge 2 commits into
Conversation
…n-table created_at work_item_completion_chart() reassigned its queryset to a bare CycleIssue/ModuleIssue id projection when scoped to a cycle or module, so grouping by created_at__date resolved against the join table's created_at (when the issue was added to the cycle/module) instead of the issue's own creation date. The "work items created" line on cycle/module charts was bucketed under the wrong date. Fix by keeping the queryset as Issue.issue_objects.filter(id__in=...), matching the pattern already used a few lines up in get_work_items_stats(), and correcting the completed_count filter from issue__state__group to state__group to match the corrected queryset shape. Adds a regression test that builds a real Workspace/Project/Cycle/Issue/ CycleIssue graph and proves the date-bucketing mismatch before the fix and the correct behavior after. Fixes GIT-229
|
Linked to Plane Work Item(s)
This comment was auto-generated by Plane |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughProject analytics chart queries now use filtered ChangesProject analytics charts
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/api/plane/app/views/analytic/project_analytics.py`:
- Line 202: Preserve the project-scoped `queryset` in the analytics view: at
`apps/api/plane/app/views/analytic/project_analytics.py#L202-L202`, filter the
existing `queryset` by `id__in=cycle_issues` instead of replacing it; apply the
same change at
`apps/api/plane/app/views/analytic/project_analytics.py#L214-L214` using
`module_issues`, retaining the initial `project_id` and `base_filters`
constraints.
🪄 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 Plus
Run ID: 9b5323a7-6595-4bd9-aa48-ee2351418349
📒 Files selected for processing (2)
apps/api/plane/app/views/analytic/project_analytics.pyapps/api/plane/tests/unit/views/test_project_analytics_chart.py
…ilter Per CodeRabbit review on makeplane#9532: filter the existing project-scoped queryset (base_filters + project_id + select_related/prefetch_related) by id__in=cycle_issues/module_issues instead of rebuilding a fresh Issue.issue_objects queryset, which silently dropped the project scoping and query optimizations.
|
Addressed in 398b55e — filtering the existing project-scoped |
Description
work_item_completion_chart()(apps/api/plane/app/views/analytic/project_analytics.py) reassigned its queryset to a bareCycleIssue/ModuleIssueid projection when scoped to a cycle or module, instead of anIssuequeryset. The subsequent.values("created_at__date")grouping then resolved against the join table'screated_at(when the issue was added to the cycle/module) rather than the issue's own creation date — so the "work items created" line on every cycle/module analytics chart was bucketed under the wrong date.The
completed_countannotation'sissue__state__grouptraversal was itself a symptom — it only made sense because the queryset was stillCycleIssue-shaped.Fix: keep the queryset as
Issue.issue_objects.filter(id__in=cycle_issues/module_issues), matching the pattern already used a few lines above inget_work_items_stats()in the same file, and correct thecompleted_countfilter fromissue__state__grouptostate__groupto match.Reproduced and verified against the real Postgres-backed test stack (
docker-compose-test.yml) — full details and before/after test output posted on the linked issue.Closes #9177 (GIT-229)
Type of Change
Screenshots and Media (if applicable)
This is a backend data-bucketing bug (dates on a chart resolve against the wrong column) rather than a visual glitch, so a screenshot wouldn't show the discrepancy — see the automated reproduction in the Test Scenarios section and on the linked issue instead.
Test Scenarios
Added
apps/api/plane/tests/unit/views/test_project_analytics_chart.py:Workspace -> Project -> Cycle -> Issue -> CycleIssuegraph with an issue created 10 days ago but added to its cycle 2 days ago.work_item_completion_chart()directly and asserts the "created" count lands under the issue's actual creation date, not the date it was added to the cycle.assert 0 == 1(work item missing from its true creation-date bucket).pytest -m unit) re-run after the fix: 343 passed, 0 failed — no regressions.References
Summary by CodeRabbit