[OSDEV-1468] Limit page parameter for GET /api/facilities.#447
Conversation
React App | Jest test suite - Code coverage reportTotal: 27.77%Your code coverage diff: 0.00% ▴ ✅ All code changes are covered |
Dedupe Hub App | Unittest test suite - Code coverage reportTotal: 56.14%Your code coverage diff: 0.00% ▴ ✅ All code changes are covered |
Contricleaner App | Unittest test suite - Code coverage reportTotal: 98.91%Your code coverage diff: 0.00% ▴ ✅ All code changes are covered |
Countries App | Unittest test suite - Code coverage reportTotal: 100%Your code coverage diff: 0.00% ▴ ✅ All code changes are covered |
Django App | Unittest test suite - Code coverage reportTotal: 79.95%Your code coverage diff: 0.03% ▴ ✅ All code changes are covered |
|
📝 WalkthroughWalkthroughThe pull request introduces significant updates for version 1.26.0 of the Open Supply Hub project, including database migrations, API endpoint modifications, new features, and bug fixes. Key changes involve the introduction of pagination settings for facilities, validation for query parameters, and enhancements to response structures. The addition of new endpoints and parameters, along with improved error handling and testing, aims to enhance the functionality and maintainability of the codebase. Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
src/django/api/serializers/facility/facility_list_page_parameter_serializer.py (1)
9-25: LGTM! Clean implementation of page parameter validation.The serializer effectively implements the page limit requirement with proper validation and user-friendly error messages.
Consider adding a docstring for the
pagefield to document its purpose and constraints:page = IntegerField( + """ + Optional page number for paginating through facilities. + Must be between 1 and DEFAULT_PAGE_LIMIT (100). + """ required=False,src/django/api/tests/test_page_limit_in_facilities_viewset_list_action.py (1)
7-36: LGTM! Good test coverage, but could be more comprehensive.The tests effectively verify the page limit functionality for both valid and invalid cases.
Consider adding these test cases for more comprehensive coverage:
def test_page_parameter_is_optional(self): response = self.client.get(self.url) self.assertEqual(response.status_code, 200) def test_page_parameter_rejects_non_integer(self): response = self.client.get(self.url, {'page': 'invalid'}) self.assertEqual(response.status_code, 400) self.assertIn('page', json.loads(response.content)) def test_page_parameter_rejects_zero(self): response = self.client.get(self.url, {'page': 0}) self.assertEqual(response.status_code, 400) self.assertIn('page', json.loads(response.content))src/django/api/views/facility/facilities_view_set.py (1)
225-230: Consider adding error logging for monitoring.While the validation logic is correct, adding error logging would help monitor invalid page parameter requests:
if not page_serializer.is_valid(): + log.info(f'Invalid page parameter: {page_serializer.errors}') raise ValidationError(page_serializer.errors)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
doc/release/RELEASE-NOTES.md(1 hunks)src/django/api/constants.py(1 hunks)src/django/api/serializers/facility/facility_list_page_parameter_serializer.py(1 hunks)src/django/api/tests/test_page_limit_in_facilities_viewset_list_action.py(1 hunks)src/django/api/views/facility/facilities_view_set.py(2 hunks)src/django/api/views/facility/facility_parameters.py(2 hunks)
🔇 Additional comments (5)
src/django/api/views/facility/facility_parameters.py (2)
36-46: LGTM! Well-documented OpenAPI parameter definition.
The page parameter is properly documented with clear description and matches the serializer implementation.
36-46: Verify impact on existing API clients.
Let's check for any existing API clients that might be affected by the new page limit.
✅ Verification successful
No impact on existing API clients expected
The verification shows that the page limit implementation is safe because:
- Frontend code doesn't make any calls to
/api/facilitiesendpoint with large page numbers - The
DEFAULT_PAGE_LIMITof 100 inFacilitiesListSettingsis consistently enforced across:- API documentation (in the parameter description)
- Input validation (in the page parameter serializer)
- Frontend test cases (max page values are within limits)
- The pagination configuration in Django settings uses even more conservative defaults:
- Default page size: 20
- Max page sizes: 50-250 depending on the paginator
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for API calls to facilities endpoint with page parameter
# Look for potential issues in tests and frontend code
# Check for page parameter usage in tests
echo "Checking tests for page parameter usage..."
rg -g '*.py' 'page.*=.*\d{3,}' tests/
rg -g '*.py' '[?&]page=\d{3,}' tests/
# Check for page parameter usage in frontend code
echo "Checking frontend code for page parameter usage..."
rg -g '*.{js,jsx,ts,tsx}' 'page.*=.*\d{3,}'
rg -g '*.{js,jsx,ts,tsx}' '[?&]page=\d{3,}'
# Check for direct API calls in documentation or examples
echo "Checking documentation for API examples..."
rg -g '*.{md,rst,txt}' '/api/facilities/.*[?&]page=\d{3,}'
Length of output: 2718
Script:
#!/bin/bash
# Let's check the specific facilities endpoint usage since previous results showed facility-lists
# Also check for any configuration or settings related to pagination
# Check for facilities endpoint usage with page parameter
echo "Checking facilities endpoint usage..."
rg -g '*.{js,jsx,ts,tsx}' '/api/facilities.*[?&]page='
# Check for pagination settings in Django
echo "Checking pagination settings..."
rg -g '*.py' 'DEFAULT_PAGE_LIMIT|page_size' src/
# Check for any other pagination-related constants
echo "Checking pagination constants..."
rg -g '*.py' 'PAGE_SIZE|PAGINATION|PER_PAGE' src/
Length of output: 1568
src/django/api/constants.py (1)
206-208: LGTM! Well-structured constant definition.
The FacilitiesListSettings class with DEFAULT_PAGE_LIMIT = 100 is appropriately placed and follows naming conventions.
src/django/api/views/facility/facilities_view_set.py (1)
94-95: LGTM! Clean import statement.
The import is properly split across lines for readability while maintaining PEP 8 compliance.
doc/release/RELEASE-NOTES.md (1)
46-46: LGTM! Clear and informative release note.
The release note clearly documents the change to limit the page parameter and explains the rationale behind it.
VadimKovalenkoSNF
left a comment
There was a problem hiding this comment.
Minor change required.
Limit the `page` parameter to `100` for the GET `/api/facilities/` endpoint. This will help prevent system downtimes, as larger pages (OFFSET) make it harder for the database to retrieve data, especially considering the large amount of data we have.



OSDEV-1468 - Limit the
pageparameter to100for the GET/api/facilities/endpoint. This will help prevent system downtimes, as larger pages (OFFSET) make it harder for the database to retrieve data, especially considering the large amount of data we have.