[WEB-8068] refactor: drop unnecessary distinct() from module listing

Address Copilot review: the project-membership join is filtered to
request.user, and ProjectMember has a unique constraint on (project, member)
where deleted_at IS NULL, so the join yields at most one row per project and
cannot duplicate Module rows. distinct() was dead weight (and a planner cost
for large workspaces). Matches the reference WorkspaceStates/WorkspaceLabels
endpoints, which use no distinct().

Also drop the distinct-focused contract test: adding a *different* project
member never fans out the request.user-filtered join, so it would pass with or
without distinct() — misleading coverage.

Co-authored-by: Plane AI <noreply@plane.so>
This commit is contained in:
Manish Gupta
2026-07-08 15:23:33 +05:30
parent f59ffbf698
commit 04a4f3ea4e
2 changed files with 0 additions and 23 deletions

View File

@@ -110,7 +110,6 @@ class WorkspaceModulesEndpoint(BaseAPIView):
)
)
.order_by(self.kwargs.get("order_by", "-created_at"))
.distinct()
)
serializer = ModuleSerializer(modules, many=True).data

View File

@@ -120,25 +120,3 @@ class TestWorkspaceCyclesModulesProjectScope:
assert response.status_code == status.HTTP_200_OK
ids = {str(row["id"]) for row in response.data}
assert str(module.id) in ids, f"Expected module {module.id} in {response.data!r}"
@pytest.mark.django_db
def test_modules_not_duplicated_for_project_member(
self, session_client, workspace, project, module
):
"""The project-member join must not duplicate a module row (.distinct())."""
# Add a second active member to the project so the reverse
# project_projectmember join fans out to more than one row.
other = User.objects.create(
email=f"peer-{uuid4().hex[:8]}@plane.so",
username=f"peer_{uuid4().hex[:8]}",
)
other.set_password("test-password")
other.save()
ProjectMember.objects.create(
project=project, member=other, workspace=workspace, role=15
)
response = session_client.get(MODULES_URL.format(slug=workspace.slug))
assert response.status_code == status.HTTP_200_OK
module_rows = [row for row in response.data if str(row["id"]) == str(module.id)]
assert len(module_rows) == 1, f"Module row duplicated: {response.data!r}"