Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pagination)!: Use PAGINATION_DEFAULT_LIMIT when limit is not provided #673

Merged
merged 2 commits into from
Dec 15, 2024

Conversation

bellini666
Copy link
Member

@bellini666 bellini666 commented Dec 15, 2024

An oversight from my side when working on #642

Fix #656

Summary by Sourcery

Fix the pagination logic to use the PAGINATION_DEFAULT_LIMIT setting when the limit is not explicitly provided in the pagination input. Update the pagination input and info classes to handle unset limits correctly and add tests to ensure the default limit is applied as expected.

Bug Fixes:

  • Ensure the default pagination limit is applied when the limit is not provided in the pagination input.

Tests:

  • Add a test to verify that the default pagination limit is used when no limit is specified in the query.

@bellini666 bellini666 self-assigned this Dec 15, 2024
Copy link
Contributor

sourcery-ai bot commented Dec 15, 2024

Reviewer's Guide by Sourcery

This PR fixes a pagination issue by ensuring that PAGINATION_DEFAULT_LIMIT is used when no limit is provided in the pagination input. The implementation modifies the pagination input structure and updates the pagination logic to handle default limits consistently.

Sequence diagram for applying pagination with default limit

sequenceDiagram
    participant Client
    participant Server
    participant Settings
    Client->>Server: Request data with pagination
    Server->>Server: Check pagination.limit
    alt limit is UNSET
        Server->>Settings: Get PAGINATION_DEFAULT_LIMIT
        Settings-->>Server: Return default limit
    end
    Server->>Server: Apply pagination with limit
    Server-->>Client: Return paginated data
Loading

Updated class diagram for pagination input and info

classDiagram
    class OffsetPaginationInfo {
        int offset = 0
        Optional~int~ limit = UNSET
    }
    class OffsetPaginationInput {
        int offset = 0
        Optional~int~ limit = UNSET
    }
    OffsetPaginationInput --|> OffsetPaginationInfo
    note for OffsetPaginationInput "OffsetPaginationInput now inherits from OffsetPaginationInfo"
Loading

File-Level Changes

Change Details Files
Refactored pagination input and info classes for better code organization
  • Moved common pagination fields to OffsetPaginationInfo class
  • Made OffsetPaginationInput inherit from OffsetPaginationInfo
  • Changed limit field default from None to UNSET
strawberry_django/pagination.py
Updated pagination logic to use default limit from settings
  • Added check for UNSET limit value
  • Retrieve PAGINATION_DEFAULT_LIMIT from settings when limit is not provided
  • Applied the same default limit logic to window pagination
strawberry_django/pagination.py
Added test coverage for default pagination limit
  • Created new test case with PAGINATION_DEFAULT_LIMIT set to 2
  • Added test scenarios for pagination with and without offset
  • Verified correct number of results returned based on default limit
tests/test_paginated_type.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @bellini666 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/test_paginated_type.py Show resolved Hide resolved
@bellini666 bellini666 force-pushed the use_pagination_default_limit branch from c487bc4 to b081016 Compare December 15, 2024 10:21
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.94%. Comparing base (e76b3fa) to head (03a5783).

Files with missing lines Patch % Lines
strawberry_django/pagination.py 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #673      +/-   ##
==========================================
- Coverage   88.98%   88.94%   -0.04%     
==========================================
  Files          41       41              
  Lines        3731     3737       +6     
==========================================
+ Hits         3320     3324       +4     
- Misses        411      413       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bellini666 bellini666 merged commit 0d59b84 into main Dec 15, 2024
24 checks passed
@bellini666 bellini666 deleted the use_pagination_default_limit branch December 15, 2024 10:26
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.

New PAGINATION_DEFAULT_LIMIT pagination setting isn't used
2 participants