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 incorrect query params type #3558

Merged

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Jul 7, 2024

Description

This is the result of my deep-dive into this comment.

Our GET query parsing method incorrectly assumed that our query parameters could be lists. As a result some of our types were sligtly incorrect and we had an unnecessary block handling the case.

Generally it would be correct that GET query parameters could contain lists (e.g. ?variables={}&variables={} could be parsed as a list). The sanic integration even contains a warning about this. However, it turns out none of our integrations interprets query parameters which are defined multiple times as lists by default (not even sanic). I manually checked every integration and also added a test to prove this. Also double-checked the graphql http spec to verify the "variables" query parameter must indeed not be a list.

(fyi: most of these frameworks provide a getlist method which can be used to explicitly interpret multi-defined GET query parameters as a list).

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

This pull request fixes the incorrect type handling of query parameters in GET requests by ensuring they are not interpreted as lists. It simplifies the internal GET query parsing logic by removing unnecessary checks, adds a test to verify the correct behavior, and includes a release note documenting the changes.

  • Bug Fixes:
    • Fixed incorrect type handling of query parameters in GET requests, ensuring they are not interpreted as lists.
  • Enhancements:
    • Simplified the internal GET query parsing logic by removing unnecessary checks for list types, improving code clarity and performance.
  • Documentation:
    • Added a release note to document the patch release and the changes made to the GET query parsing logic.
  • Tests:
    • Added a test to verify that query parameters are never interpreted as lists across all integrations.

Copy link
Contributor

sourcery-ai bot commented Jul 7, 2024

Reviewer's Guide by Sourcery

This pull request simplifies the handling of GET query parameters by removing unnecessary list handling and updating the QueryParams type. It also adds a test to ensure query parameters are never interpreted as lists, and includes release notes for the patch.

File-Level Changes

Files Changes
strawberry/sanic/views.py
strawberry/http/base.py
strawberry/flask/views.py
strawberry/http/types.py
Simplified the handling of query parameters by removing unnecessary list handling and updating the QueryParams type.
tests/http/test_query.py Added a test to ensure query parameters are never interpreted as lists.

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 @DoctorJohn - 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: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

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/sanic/views.py Show resolved Hide resolved
strawberry/http/base.py Show resolved Hide resolved
tests/http/test_query.py Show resolved Hide resolved
tests/http/test_query.py Show resolved Hide resolved
tests/http/test_query.py Show resolved Hide resolved
RELEASE.md Show resolved Hide resolved
@botberry
Copy link
Member

botberry commented Jul 7, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release removes an unnecessary check from our internal GET query parsing logic making it simpler and (insignificantly) faster.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @NucleonJohn for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

@botberry
Copy link
Member

botberry commented Jul 7, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release removes an unnecessary check from our internal GET query parsing logic making it simpler and (insignificantly) faster.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @NucleonJohn for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.58%. Comparing base (d2c0fb4) to head (36da65e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3558      +/-   ##
==========================================
+ Coverage   96.57%   96.58%   +0.01%     
==========================================
  Files         524      524              
  Lines       33630    33632       +2     
  Branches     5578     5577       -1     
==========================================
+ Hits        32478    32484       +6     
+ Misses        916      914       -2     
+ Partials      236      234       -2     

Copy link

codspeed-hq bot commented Jul 7, 2024

CodSpeed Performance Report

Merging #3558 will not alter performance

Comparing DoctorJohn:fix-incorrect-query-params-type (36da65e) with main (d2c0fb4)

Summary

✅ 13 untouched benchmarks

@DoctorJohn DoctorJohn force-pushed the fix-incorrect-query-params-type branch from 98b3698 to 36da65e Compare July 7, 2024 17:03
Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Thank you! 😊

@patrick91 patrick91 merged commit c25da89 into strawberry-graphql:main Jul 8, 2024
64 checks passed
@DoctorJohn DoctorJohn deleted the fix-incorrect-query-params-type branch November 20, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants