Skip to content

[bug] Public API: module completed_issues and other state counts are always 0 or 1 #10253

Closed

Description

@SynapseTrace

Summary

GET /api/v1/workspaces/{slug}/projects/{project_id}/modules/ and the module detail endpoint return completed_issues, cancelled_issues, started_issues, unstarted_issues and backlog_issues as 0 or 1, whatever the real number is. total_issues is correct. The web app shows the correct numbers.

Cause

In apps/api/plane/api/views/module.py (list, retrieve and archived views), each state count is:

completed_issues=Count(
    "issue_module__issue__state__group",
    filter=Q(issue_module__issue__state__group="completed", ...),
    distinct=True,
)

The query counts the distinct values of state__group, and the filter fixes that same field to one value. So COUNT(DISTINCT ...) can only return 0 or 1. The count must be on the issue, for example Count("issue_module__issue", filter=..., distinct=True).

The web view apps/api/plane/app/views/module/base.py uses a different query and is correct. #8595 fixed the web path but did not change the public API, so the two now differ.

Reproduce

  1. Create a module with 3 issues.
  2. Move all 3 issues to a Completed state.
  3. Call GET /api/v1/workspaces/{slug}/projects/{project_id}/modules/{module_id}/.
  4. Expected: completed_issues: 3. Actual: completed_issues: 1.

We saw this on a self-hosted instance: a module with 10 completed issues of 18 returned completed_issues: 1, and modules with 2 and 3 cancelled issues returned cancelled_issues: 1.

Fix status

The code is unchanged on preview and master (checked 2026-11-10). Open PR #9275 (performance) replaces these annotations with _module_issue_count_subquery(), which counts ModuleIssue rows and so fixes this bug as a side effect. Merging #9275, or a one-line change for each annotation, closes this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions