Skip to content

[GIT-229] fix: bucket cycle/module analytics chart by Issue.created_at - #9532

Open
blockgroot wants to merge 2 commits into
makeplane:previewfrom
blockgroot:fix/git-229-analytics-cycle-module-date-bucketing
Open

[GIT-229] fix: bucket cycle/module analytics chart by Issue.created_at#9532
blockgroot wants to merge 2 commits into
makeplane:previewfrom
blockgroot:fix/git-229-analytics-cycle-module-date-bucketing

Conversation

@blockgroot

@blockgroot blockgroot commented Aug 3, 2026

Copy link
Copy Markdown

Description

work_item_completion_chart() (apps/api/plane/app/views/analytic/project_analytics.py) reassigned its queryset to a bare CycleIssue/ModuleIssue id projection when scoped to a cycle or module, instead of an Issue queryset. The subsequent .values("created_at__date") grouping then resolved against the join table's created_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_count annotation's issue__state__group traversal was itself a symptom — it only made sense because the queryset was still CycleIssue-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 in get_work_items_stats() in the same file, and correct the completed_count filter from issue__state__group to state__group to 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

  • 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

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:

  • Builds a real Workspace -> Project -> Cycle -> Issue -> CycleIssue graph with an issue created 10 days ago but added to its cycle 2 days ago.
  • Calls 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.
  • Before the fix: fails with assert 0 == 1 (work item missing from its true creation-date bucket).
  • After the fix: passes.
  • Full unit suite (pytest -m unit) re-run after the fix: 343 passed, 0 failed — no regressions.

References

Summary by CodeRabbit

  • Bug Fixes
    • Fixed completion charts filtered by cycles or modules to accurately aggregate issue states and completion counts.
    • Corrected chart date bucketing so items are grouped by when the issue was created, rather than when it was added to a cycle.

…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
@CLAassistant

CLAassistant commented Aug 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@makeplane

makeplane Bot commented Aug 3, 2026

Copy link
Copy Markdown

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dcfe1f1c-458c-4cbf-9736-452241d17485

📥 Commits

Reviewing files that changed from the base of the PR and between 634e3a2 and 398b55e.

📒 Files selected for processing (1)
  • apps/api/plane/app/views/analytic/project_analytics.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/plane/app/views/analytic/project_analytics.py

📝 Walkthrough

Walkthrough

Project analytics chart queries now use filtered Issue querysets and the direct state relation. A regression test verifies that cycle completion charts bucket items by issue creation date.

Changes

Project analytics charts

Layer / File(s) Summary
Correct filtered chart querysets
apps/api/plane/app/views/analytic/project_analytics.py
Cycle- and module-filtered charts now resolve filtered IDs to Issue records. Completed-item aggregation now uses the direct state relation.
Validate issue date bucketing
apps/api/plane/tests/unit/views/test_project_analytics_chart.py
A database regression test verifies that charts use Issue.created_at and exclude the cycle-assignment date.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: dheeru0198, pablohashescobar

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the bug, identifies the fix, records the test scenarios and results, and includes the change type and references.
Title check ✅ Passed The title clearly identifies the analytics chart date-bucketing fix and references the related work item.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65f4a99 and 634e3a2.

📒 Files selected for processing (2)
  • apps/api/plane/app/views/analytic/project_analytics.py
  • apps/api/plane/tests/unit/views/test_project_analytics_chart.py

Comment thread apps/api/plane/app/views/analytic/project_analytics.py Outdated
…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.
@blockgroot

Copy link
Copy Markdown
Author

Addressed in 398b55e — filtering the existing project-scoped queryset (with select_related/prefetch_related intact) by id__in=cycle_issues/module_issues instead of rebuilding a fresh Issue.issue_objects queryset. Re-ran the full unit suite after the change: 343 passed, 0 regressions.

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.

Analytics Charts for Cycles and Modules Show Wrong Data — Queryset Anchored to Wrong Model

2 participants