Skip to content

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

Description

@R0hit-Sriram

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I view analytics charts filtered by a cycle or module, the daily stats chart shows incorrect data. The queryset is reassigned from Issue objects to a flat .values_list("issue_id", flat=True) queryset anchored to CycleIssue/ModuleIssue. Subsequent .values("created_at__date") calls then use the join table's created_at instead of Issue.created_at, producing wrong date groupings in the chart.

Code pattern:
cycle_issues = CycleIssue.objects.filter(...).values_list("issue_id", flat=True)
queryset = cycle_issues # queryset is now CycleIssue IDs, not Issue objects
queryset.values("created_at__date") # uses CycleIssue.created_at, not Issue.created_at

What I expect is that analytics charts for cycles and modules correctly reflect issue creation dates.

File: apps/api/plane/app/views/analytic/project_analytics.py, lines 202 and 214

Steps to reproduce

  1. Open Analytics for a project
    1. Filter the chart by a specific cycle or module
    1. Observe the daily chart data doesn't match the actual issue creation dates

Environment

Production

Browser

Google Chrome

Variant

Cloud

Version

v0.17.0-dev

Activity

  1. sauravdas-cs commented on Jul 2, 2026

    @sauravdas-cs

    Could you let us know if you're on the Community Edition? Also, could you share a screen recording of the issue? We tried reproducing it on our end but couldn't, that'll help us look into it further.

  2. blockgroot commented on Aug 3, 2026

    @blockgroot

    Hi @sauravdas-cs — I dug into this and can answer both questions directly, plus give you something more conclusive than a screen recording for this particular bug.

    Community Edition? Yes — reproduced against a clean checkout of this repo (makeplane/plane, HEAD 65f4a996), no EE/Cloud-only code involved.

    Why not a screen recording: this isn't a visual glitch — the chart renders fine, it's just keyed to the wrong date under the hood. A recording would show a chart that "looks correct" unless the viewer already knows which exact date each work item was created on vs. added to the cycle, which is exactly what makes it hard to catch from the UI and easy to miss in manual testing. So instead I built a deterministic, automated reproduction that isolates the data bug directly — I think it'll be faster for you to verify than a video.

    Root cause

    apps/api/plane/app/views/analytic/project_analytics.py, work_item_completion_chart():

    if cycle_id is not None:
        cycle_issues = CycleIssue.objects.filter(**self.filters["base_filters"], cycle_id=cycle_id).values_list(
            "issue_id", flat=True
        )
        ...
        queryset = cycle_issues   # <- still a CycleIssue queryset, not Issue

    Later:

    daily_stats = (
        queryset.values("created_at__date")   # <- CycleIssue.created_at, not Issue.created_at
        .annotate(
            created_count=Count("id"),
            completed_count=Count("id", filter=Q(issue__state__group="completed")),  # only works because queryset is still CycleIssue-shaped
        )
        ...
    )

    Because queryset was never converted from the CycleIssue/ModuleIssue id projection into an actual Issue queryset, created_at__date resolves against the join table's created_at (i.e., when the issue was added to the cycle/module) instead of the issue's own creation date. The completed_count annotation's issue__state__group traversal is itself a tell — it only makes sense if the queryset is still CycleIssue, confirming the mix-up. Same bug, same shape, in the module_id branch.

    Reproduction (automated, run locally against the real stack)

    Added apps/api/plane/tests/unit/views/test_project_analytics_chart.py: builds a real Workspace → Project → Cycle → Issue → CycleIssue graph in Postgres via the repo's own docker-compose-test.yml stack, with an issue created 10 days ago but added to its cycle 2 days ago, then calls work_item_completion_chart() directly.

    Before the fix, run via:

    docker compose -f docker-compose-test.yml run --rm api-tests \
      pytest plane/tests/unit/views/test_project_analytics_chart.py -vv
    
    AssertionError: expected the cycle chart to bucket the work item under the date it was
    actually created (2026-07-24), but got 0 -- it is bucketing by CycleIssue.created_at
    (when the issue was added to the cycle) instead of Issue.created_at
    assert 0 == 1
    

    After the fix (swap the queryset to Issue.issue_objects.filter(id__in=cycle_issues/module_issues), matching the pattern already used a few lines up in get_work_items_stats(), and correct completed_count's filter from issue__state__group to state__group since the queryset shape changes):

    1 passed in 1.37s
    

    Full unit suite afterward: 343 passed, 0 failed (no regressions).

    I'll open a PR with this fix + test shortly — happy to adjust anything if you want a different approach to the queryset swap.

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

Metadata

Metadata

Assignees

Labels

plane🐛bug

Type

Fields

Edition

None yet

Version

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions