Skip to content

[OSDEV-1468] Limit page parameter for GET /api/facilities.#447

Merged
vladsha-dev merged 3 commits intomainfrom
OSDEV-1468-limit-page-parameter-for-get-api-facilities
Dec 9, 2024
Merged

[OSDEV-1468] Limit page parameter for GET /api/facilities.#447
vladsha-dev merged 3 commits intomainfrom
OSDEV-1468-limit-page-parameter-for-get-api-facilities

Conversation

@vladsha-dev
Copy link
Contributor

@vladsha-dev vladsha-dev commented Dec 6, 2024

OSDEV-1468 - 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.

@vladsha-dev vladsha-dev self-assigned this Dec 6, 2024
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev marked this pull request as draft December 6, 2024 17:19
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:19 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:21 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Dec 6, 2024

React App | Jest test suite - Code coverage report

Total: 27.77%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:25 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Dec 6, 2024

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:26 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Dec 6, 2024

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:27 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Dec 6, 2024

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 6, 2024 17:36 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Dec 6, 2024

Django App | Unittest test suite - Code coverage report

Total: 79.95%

Your code coverage diff: 0.03% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:42 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:42 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:44 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:44 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:44 — with GitHub Actions Inactive
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2024

@vladsha-dev vladsha-dev marked this pull request as ready for review December 9, 2024 13:45
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment December 9, 2024 13:46 — with GitHub Actions Inactive
@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2024

📝 Walkthrough

Walkthrough

The 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

File Path Change Summary
doc/release/RELEASE-NOTES.md Updated release notes for version 1.26.0, detailing database migration for ModerationEvent, API changes including new endpoints and breaking changes, architecture changes for database snapshots, and bug fixes.
src/django/api/constants.py Added class FacilitiesListSettings with constant DEFAULT_PAGE_LIMIT set to 100 for pagination settings.
src/django/api/serializers/facility/facility_list_page_parameter_serializer.py Introduced FacilityListPageParameterSerializer to validate page query parameter for facilities list, with constraints and custom error messages.
src/django/api/tests/test_page_limit_in_facilities_viewset_list_action.py Added TestPageLimitInFacilitiesViewsetListAction class with tests for enforcing page limit in facilities viewset, validating responses for valid and exceeding page numbers.
src/django/api/views/facility/facilities_view_set.py Updated list method in FacilitiesViewSet to include validation using FacilityListPageParameterSerializer, enhancing error handling for pagination parameters.
src/django/api/views/facility/facility_parameters.py Added page parameter to facilities_list_parameters for pagination, referencing FacilitiesListSettings.DEFAULT_PAGE_LIMIT.

Possibly related PRs

Suggested reviewers

  • Innavin369
  • roman-stolar
  • VadimKovalenkoSNF
  • mazursasha1990

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 page field 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

📥 Commits

Reviewing files that changed from the base of the PR and between 39c89b8 and 6a92c9d.

📒 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/facilities endpoint with large page numbers
  • The DEFAULT_PAGE_LIMIT of 100 in FacilitiesListSettings is 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.

Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change required.

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@roman-stolar roman-stolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@vladsha-dev vladsha-dev merged commit 2c1e40b into main Dec 9, 2024
@vladsha-dev vladsha-dev deleted the OSDEV-1468-limit-page-parameter-for-get-api-facilities branch December 9, 2024 14:15
protsack-stephan pushed a commit that referenced this pull request Apr 12, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants