:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tasks): honor limit and offset on the channel list (#93917)
posthog[bot]9774ce8a1929
diff --git a/products/tasks/backend/presentation/views/channels_api.py b/products/tasks/backend/presentation/views/channels_api.pyindex c4b1653363fd..8e832f1a9cf4 100644--- a/products/tasks/backend/presentation/views/channels_api.py+++ b/products/tasks/backend/presentation/views/channels_api.py@@ -1,4 +1,4 @@-from typing import Any+from typing import Any, castfrom uuid import UUIDfrom drf_spectacular.openapi import AutoSchema@@ -7,6 +7,7 @@ from rest_framework import status, viewsetsfrom rest_framework.authentication import SessionAuthenticationfrom rest_framework.decorators import actionfrom rest_framework.exceptions import NotFound, PermissionDenied, ValidationError+from rest_framework.pagination import LimitOffsetPaginationfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Response@@ -55,6 +56,17 @@ from products.tasks.backend.presentation.serializers import (TeachingCanvasSerializer,)++class ChannelListPagination(LimitOffsetPagination):+ """Opt-in paging for the channel list. ``default_limit = None`` keeps the plain+ array that clients read today when no ``limit`` is sent; a caller that asks for a+ page gets the standard ``count``/``next``/``previous`` envelope instead. ``list``+ instantiates it directly, so the other paged actions on the viewset keep the+ project-wide paginator."""++ default_limit = None++# Shared by the PUT and PATCH verbs on /instructions/ — same request/response contract,# PATCH is an alias for clients that can't send PUT.PUBLISH_INSTRUCTIONS_SCHEMA_KWARGS: dict[str, Any] = {@@ -119,12 +131,17 @@ class ChannelViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):description=("All live public channels plus the requester's personal #me channel when it exists, ""sorted by name. Listing does not provision; call provision_defaults to create the "- "default channels."+ "default channels. Send `limit` (with `offset`) for one page and a `count`/`next` "+ "envelope; without `limit` the response is the full array of channels."),)def list(self, request, *args, **kwargs):channels = tasks_facade.list_channels(self.team_id, self._user_id())- return Response(ChannelSerializer(channels, many=True).data)+ paginator = ChannelListPagination()+ page = paginator.paginate_queryset(cast(Any, channels), request, view=self)+ if page is None:+ return Response(ChannelSerializer(channels, many=True).data)+ return paginator.get_paginated_response(ChannelSerializer(page, many=True).data)@extend_schema(request=None,diff --git a/products/tasks/backend/tests/test_channels_api.py b/products/tasks/backend/tests/test_channels_api.pyindex d90c94c1b8e6..a8eac7708147 100644--- a/products/tasks/backend/tests/test_channels_api.py+++ b/products/tasks/backend/tests/test_channels_api.py@@ -91,6 +91,28 @@ class ChannelsAPITestCase(TestCase):self.assertEqual(response.json(), [])self.assertFalse(Channel.objects.for_team(self.team.id).exists())+ def test_list_pages_when_limit_is_given(self):+ for name in ("alpha", "bravo", "charlie"):+ self.client.post(self._channels_url(), {"name": name})++ first = self.client.get(self._channels_url(), {"limit": 2})+ self.assertEqual(first.status_code, status.HTTP_200_OK)+ body = first.json()+ self.assertEqual(body["count"], 3)+ self.assertEqual([channel["name"] for channel in body["results"]], ["alpha", "bravo"])+ self.assertIsNotNone(body["next"])++ second = self.client.get(self._channels_url(), {"limit": 2, "offset": 2})+ self.assertEqual([channel["name"] for channel in second.json()["results"]], ["charlie"])+ self.assertIsNone(second.json()["next"])++ def test_list_returns_every_channel_without_a_limit(self):+ for name in ("alpha", "bravo", "charlie"):+ self.client.post(self._channels_url(), {"name": name})++ response = self.client.get(self._channels_url())+ self.assertEqual([channel["name"] for channel in response.json()], ["alpha", "bravo", "charlie"])+def test_personal_channels_are_per_user(self):mine = self._provision()["channels"]other_client = APIClient()diff --git a/products/tasks/docs/CHANNELS.md b/products/tasks/docs/CHANNELS.mdindex 9a9d3e547384..e41075fa40d8 100644--- a/products/tasks/docs/CHANNELS.md+++ b/products/tasks/docs/CHANNELS.md@@ -89,8 +89,10 @@ membership without adding permissions to Task.### `/api/projects/{id}/task_channels/`- `GET /` — list channels: all live public channels plus the requester's- personal channel. Listing lazily `get_or_create`s the personal `#me` channel,- so every user always has one.+ personal `#me` channel when it exists. Listing does not provision; call+ `provision_defaults` to create the default channels. Paging is opt-in:+ `?limit=&offset=` returns one page in a `count`/`next`/`previous` envelope,+ and a request without `limit` returns every channel as a plain array.- `POST / {name}` — resolve-or-create a public channel by name(`get_or_create`, so concurrent creates and name-bridging are race-safe).- `PATCH /{id}/ {name}` - any project member can rename or configure a public channel. Private `#me` spaces cannot be renamed.diff --git a/products/tasks/frontend/generated/api.ts b/products/tasks/frontend/generated/api.tsindex c9dc5dee657a..3f48e57a7622 100644--- a/products/tasks/frontend/generated/api.ts+++ b/products/tasks/frontend/generated/api.ts@@ -784,7 +784,7 @@ export const getTaskChannelsListUrl = (projectId: string, params?: TaskChannelsL}/**- * All live public channels plus the requester's personal #me channel when it exists, sorted by name. Listing does not provision; call provision_defaults to create the default channels.+ * All live public channels plus the requester's personal #me channel when it exists, sorted by name. Listing does not provision; call provision_defaults to create the default channels. Send `limit` (with `offset`) for one page and a `count`/`next` envelope; without `limit` the response is the full array of channels.* @summary List channels*/export const taskChannelsList = async (diff --git a/products/tasks/mcp/tools.yaml b/products/tasks/mcp/tools.yamlindex 5f3948791574..75ae0993f01a 100644--- a/products/tasks/mcp/tools.yaml+++ b/products/tasks/mcp/tools.yaml@@ -79,7 +79,9 @@ tools:title: List channelsdescription: >List the project's channels (public channels plus the requester's personal #me channel). Use this to resolve- a channel id from its name before creating or listing canvases or reading instructions.+ a channel id from its name before creating or listing canvases or reading instructions. A project can hold+ hundreds of channels, so pass `limit` (with `offset`) to read one page: the paged response carries `count`+ and `next`, and without `limit` you get every channel in one array.channel-retrieve:operation: task_channels_retrieveenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 5fec96a9d6f3..f6f78a5f17ed 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -1671,7 +1671,7 @@"feature_flag_behavior": "disable"},"channel-list": {- "description": "List the project's channels (public channels plus the requester's personal #me channel). Use this to resolve a channel id from its name before creating or listing canvases or reading instructions.",+ "description": "List the project's channels (public channels plus the requester's personal #me channel). Use this to resolve a channel id from its name before creating or listing canvases or reading instructions. A project can hold hundreds of channels, so pass `limit` (with `offset`) to read one page: the paged response carries `count` and `next`, and without `limit` you get every channel in one array.","category": "Tasks","feature": "tasks","summary": "List channels",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 46ca0a676c55..4c0a4cfb1bfd 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -1686,7 +1686,7 @@"feature_flag_behavior": "disable"},"channel-list": {- "description": "List the project's channels (public channels plus the requester's personal #me channel). Use this to resolve a channel id from its name before creating or listing canvases or reading instructions.",+ "description": "List the project's channels (public channels plus the requester's personal #me channel). Use this to resolve a channel id from its name before creating or listing canvases or reading instructions. A project can hold hundreds of channels, so pass `limit` (with `offset`) to read one page: the paged response carries `count` and `next`, and without `limit` you get every channel in one array.","category": "Tasks","feature": "tasks","summary": "List channels",diff --git a/services/mcp/src/generated/tasks/api.ts b/services/mcp/src/generated/tasks/api.tsindex 669c327082b6..1553cb47d59b 100644--- a/services/mcp/src/generated/tasks/api.ts+++ b/services/mcp/src/generated/tasks/api.ts@@ -735,7 +735,7 @@ export const LoopsRunsRetrieveQueryParams = () => zod.object({})/**- * All live public channels plus the requester's personal #me channel when it exists, sorted by name. Listing does not provision; call provision_defaults to create the default channels.+ * All live public channels plus the requester's personal #me channel when it exists, sorted by name. Listing does not provision; call provision_defaults to create the default channels. Send `limit` (with `offset`) for one page and a `count`/`next` envelope; without `limit` the response is the full array of channels.* @summary List channels*/export const TaskChannelsListParams = () => zod.object({