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: Avoid pagination failures when filtering connection by last without before/after #585

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

bellini666
Copy link
Member

@bellini666 bellini666 commented Jul 14, 2024

Fix #576

Summary by Sourcery

This pull request addresses an issue with pagination failures when filtering connections by 'last' without 'before' or 'after' parameters. It includes new test cases to validate the correct behavior of window pagination under various conditions.

  • Bug Fixes:
    • Fixed pagination failures when filtering connections by 'last' without 'before' or 'after' parameters.
  • Tests:
    • Added test cases for window pagination to ensure correct behavior with and without limits.

@bellini666 bellini666 self-assigned this Jul 14, 2024
Copy link
Contributor

sourcery-ai bot commented Jul 14, 2024

Reviewer's Guide by Sourcery

This pull request addresses issue #576 by enhancing the pagination logic in the apply_window_pagination function to handle cases where the limit is set to sys.maxsize or -1, which are used to mimic 'no limit' scenarios. Additionally, new tests were added to verify the correct behavior of the pagination logic under these conditions. Minor updates were also made to existing tests to improve their robustness.

File-Level Changes

Files Changes
tests/test_pagination.py
strawberry_django/pagination.py
Enhanced pagination logic and added corresponding tests to ensure proper handling of edge cases with offset and limit.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

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: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 5 issues 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 to tell me if it was helpful.

strawberry_django/pagination.py Show resolved Hide resolved
strawberry_django/pagination.py Show resolved Hide resolved
tests/test_pagination.py Show resolved Hide resolved
assert fruit._strawberry_total_count == 10 # type: ignore


@pytest.mark.parametrize("limit", [-1, sys.maxsize])
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Add a test case for limit set to zero.

It would be useful to add a test case where the limit is set to zero to verify that the pagination logic correctly handles this scenario.

Suggested change
@pytest.mark.parametrize("limit", [-1, sys.maxsize])
@pytest.mark.parametrize("limit", [-1, 0, sys.maxsize])

tests/test_pagination.py Show resolved Hide resolved

@pytest.mark.parametrize("limit", [-1, sys.maxsize])
@pytest.mark.django_db(transaction=True)
def test_apply_window_pagination_with_no_limites(limit):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick (testing): Typo in test function name.

The function name test_apply_window_pagination_with_no_limites contains a typo. It should be test_apply_window_pagination_with_no_limits.

tests/test_queries.py Show resolved Hide resolved
Comment on lines +110 to +111
for i in range(10):
models.Fruit.objects.create(name=f"fruit{i}", color=color)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

tests/test_pagination.py Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.82%. Comparing base (2897bab) to head (253f72c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #585      +/-   ##
==========================================
+ Coverage   88.79%   88.82%   +0.03%     
==========================================
  Files          41       41              
  Lines        3597     3598       +1     
==========================================
+ Hits         3194     3196       +2     
+ Misses        403      402       -1     

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

@bellini666 bellini666 merged commit c2c3790 into main Jul 14, 2024
22 checks passed
@bellini666 bellini666 deleted the fix_full_result_set branch July 14, 2024 14:25
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.

Query optimizer raises FullResultSet exception when using PostgreSQL
2 participants