You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(environments): let the environments list take a page_size - #8913
EnvironmentViewSet had no pagination_class, so it fell back to DRF's global default of 10 results per page and ignored the page_size query parameter. PR #8654 worked around this on the frontend with a fetchAllPages / getAllEnvironments helper.
Changes
Backend (api/environments/views.py)
Set pagination_class = CustomPagination on EnvironmentViewSet, matching the pattern used by features, identities, and experiments viewsets.
Frontend
Remove the getAllEnvironments RTK endpoint (which used fetchAllPages to paper over the missing server-side pagination).
Switch useGroupedBreakdown to useGetEnvironmentsQuery and read .results from the standard paged response.
Remove the now-unused getAllEnvironments request and response types.
test_list_environments__returns_paginated_response: verifies the list action returns a paginated envelope (results, count).
test_list_environments__page_size_param_is_respected: verifies page_size controls result count.
Notes
CustomPagination defaults to page_size=999 and max_page_size=999, so existing callers that do not pass page_size get up to 999 environments per page - well above any realistic project size, so there is no regression for callers that relied on the old unpaginated response shape.
EnvironmentViewSet had no pagination_class, so it fell back to DRF's
default of 10 per page and ignored the page_size query parameter.
- Set pagination_class = CustomPagination on EnvironmentViewSet so
callers can pass page_size and receive a standard paginated response
- Drop the getAllEnvironments RTK endpoint (which used fetchAllPages to
work around the missing pagination) in favour of getEnvironments
- Update useGroupedBreakdown to use useGetEnvironmentsQuery and read
.results from the paged response
- Remove the now-unused getAllEnvironments request/response types
- Add backend tests covering the paginated response shape and that
page_size is respected
The environment list endpoint now uses CustomPagination. Tests cover project filtering, result counts, page sizes, page links and the maximum page size. The frontend removes the all-environments query and its request and response types. The usage breakdown now uses the project-scoped environments query and reads environment names from its results array.
The pagination change is mergeable with bounded follow-up: projects with more than 999 permitted environments can show existing environments as “Deleted environments” in usage breakdowns. Fetching all pages would correct those labels.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
nl -ba api/app_analytics/views.py | sed -n '1,135p'
nl -ba api/environments/serializers.py | sed -n '1,200p'
nl -ba api/environments/models.py | sed -n '75,180p'
nl -ba frontend/web/components/pages/usage/components/UsageBreakdown/UsageBreakdown.tsx
nl -ba frontend/web/components/pages/usage/components/UsageBreakdown/breakdownView.ts | sed -n '1,120p'
Repository: Flagsmith/flagsmith
Length of output: 22769
Fetch every environment page for the usage breakdown.
When a project has more than 999 permitted environments, usage for an environment on a later page can appear under Deleted environments. Fetch all environment pages before building the name lookup.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
The current test detects the former 10-result default, but not a change from 999 to 11. Consider a separate test with 1,000 environments that checks for 999 results and a next page.
The reason will be displayed to describe this comment to others. Learn more.
Trivial · Functional Correctness · Low value
Supported by static analysis
Script executed:
sed -n '1430,1520p' api/tests/unit/environments/test_unit_environments_views.py
rg -n 'max_page_size|10000|999' api/tests/unit/app api/tests/unit/environments api/app/pagination.py
Repository: Flagsmith/flagsmith
Length of output: 5542
Script executed:
printf'%s\n''--- Pagination and environment list test ---'
nl -ba api/app/pagination.py | sed -n '1,40p'
nl -ba api/environments/views.py | sed -n '55,115p'
nl -ba api/tests/unit/environments/test_unit_environments_views.py | sed -n '1385,1508p'printf'%s\n''--- Environment model location ---'
rg -n 'class Environment\(|def save\(|post_save|pre_save|Environment\.objects\.bulk_create' api/environments api/tests/unit/environments --glob '*.py'| sed -n '1,110p'
Repository: Flagsmith/flagsmith
Length of output: 10404
Script executed:
printf'%s\n''--- Environment model and creation hooks ---'
nl -ba api/environments/models.py | sed -n '65,230p'
rg -n -F -e 'sender=Environment' -e 'sender = Environment' -e 'post_save.connect' -e 'pre_save.connect' api/environments api/features api/projects --glob '*.py'||test"$?" -eq 1
printf'%s\n''--- Edge identity limit test ---'
nl -ba api/tests/integration/edge_api/identities/test_edge_identity_viewset.py | sed -n '220,265p'
Repository: Flagsmith/flagsmith
Length of output: 11432
Test the configured page-size limit.
The patched maximum tests capping but does not protect the configured limit of 999. Add an unpatched test with more than 999 environments and page_size=10000. Assert that the response contains 999 results and a next page.
The reason will be displayed to describe this comment to others. Learn more.
Trivial · Functional Correctness · Low value
Supported by static analysis
Script executed:
sed -n '1430,1520p' api/tests/unit/environments/test_unit_environments_views.py
rg -n 'next.*]|next.*link|page_2_data' api/tests/unit/environments
Repository: Flagsmith/flagsmith
Length of output: 4379
Script executed:
rg -n -F -e 'CustomPagination' -e '["next"]' -e "['next']" api/tests/unit/environments api/tests/integration 2>/dev/null;printf'\n--- identity pagination test ---\n'; nl -ba api/tests/unit/environments/identities/test_unit_identities_views.py | sed -n '255,320p';printf'\n--- pagination implementation ---\n'; nl -ba api/app/pagination.py | sed -n '1,100p';printf'\n--- endpoint ---\n'; nl -ba api/environments/views.py | sed -n '65,135p';printf'\n--- changed test ---\n'; nl -ba api/tests/unit/environments/test_unit_environments_views.py | sed -n '1400,1515p'
Repository: Flagsmith/flagsmith
Length of output: 15262
Follow the page-two link in the test.
The test requests page three independently, so it accepts a next link that omits parameters or points back to page two. Follow page_2_data["next"] to check that the link returns the final environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
EnvironmentViewSethad nopagination_class, so it fell back to DRF's global default of 10 results per page and ignored thepage_sizequery parameter. PR #8654 worked around this on the frontend with afetchAllPages/getAllEnvironmentshelper.Changes
Backend (
api/environments/views.py)pagination_class = CustomPaginationonEnvironmentViewSet, matching the pattern used by features, identities, and experiments viewsets.Frontend
getAllEnvironmentsRTK endpoint (which usedfetchAllPagesto paper over the missing server-side pagination).useGroupedBreakdowntouseGetEnvironmentsQueryand read.resultsfrom the standard paged response.getAllEnvironmentsrequest and response types.Tests (
api/tests/unit/environments/test_unit_environments_views.py)test_list_environments__returns_paginated_response: verifies the list action returns a paginated envelope (results,count).test_list_environments__page_size_param_is_respected: verifiespage_sizecontrols result count.Notes
CustomPaginationdefaults topage_size=999andmax_page_size=999, so existing callers that do not passpage_sizeget up to 999 environments per page - well above any realistic project size, so there is no regression for callers that relied on the old unpaginated response shape.