[WEB-8095] fix: distinct() on page-version detail lookup as a MultipleObjectsReturned guard

Address CodeRabbit review on #9380. The active-link filter already keeps
the page__project_pages join to a single row via the partial-unique
constraint, but add distinct() to the detail get() as defense in depth so
the join can never surface MultipleObjectsReturned (a 500) even if that
invariant were ever violated.

Co-authored-by: Plane AI <noreply@plane.so>
This commit is contained in:
Manish Gupta
2026-07-09 15:42:32 +05:30
parent 01e6ef8873
commit 8882731a15

View File

@@ -23,13 +23,19 @@ class PageVersionEndpoint(BaseAPIView):
# for the URL project so a page belonging to (or removed from)
# another project cannot be read via this endpoint (GHSA-g49r /
# GHSA-ghcr). The active-link partial-unique constraint keeps the
# join to a single row, so get() stays unambiguous.
page_version = PageVersion.objects.get(
workspace__slug=slug,
page__project_pages__project_id=project_id,
page__project_pages__deleted_at__isnull=True,
page_id=page_id,
pk=pk,
# join to a single row; distinct() is a defensive guard so the
# page__project_pages join can never make get() raise
# MultipleObjectsReturned (a 500).
page_version = (
PageVersion.objects.filter(
workspace__slug=slug,
page__project_pages__project_id=project_id,
page__project_pages__deleted_at__isnull=True,
page_id=page_id,
pk=pk,
)
.distinct()
.get()
)
# Serialize the page version
serializer = PageVersionDetailSerializer(page_version)