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

refactor: Remove guardian ObjectPermissionChecker monkey patch #631

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

bellini666
Copy link
Member

@bellini666 bellini666 commented Sep 24, 2024

This is an old monkey patch that was introduced back when this code used to live in strawberry-django-plus, with the intention of avoiding too many queries to the database when fetching permissions.

This ended up causing an issue, as checking for a permission would cache the result, and later when trying to modify the permissions and checking those again would return the cached result instead.

This seems like to not be required anymore as well, based on the fact that we have a lot of unit tests that test the permissioning stuff with guardian, while also ensuring that the number of db requests are known, and none presented any issues.

Summary by Sourcery

Refactor the code to remove the custom monkey patch for ObjectPermissionChecker, which was causing caching issues with permission checks. This change relies on existing unit tests to ensure that permission handling remains efficient and correct without the patch.

Enhancements:

  • Remove the custom monkey patch for ObjectPermissionChecker to prevent caching issues with permission checks.

This is an old monkey patch that was introduced back when this code
used to live in `strawberry-django-plus`, with the intention of avoiding
too many queries to the database when fetching permissions.

This ended up causing an issue, as checking for a permission would
cache the result, and later when trying to modify the permissions and
checking those again would return the cached result instead.

This seems like to not be required anymore as well, based on the fact
that we have a lot of unit tests that test the permissioning stuff
with guardian, while also ensuring that the number of db requests
are known, and none presented any issues.
@bellini666 bellini666 self-assigned this Sep 24, 2024
Copy link
Contributor

sourcery-ai bot commented Sep 24, 2024

Reviewer's Guide by Sourcery

This pull request removes a legacy monkey patch for the ObjectPermissionChecker in the guardian integration. The patch was originally implemented to reduce database queries when fetching permissions, but it caused issues with caching and is no longer necessary due to extensive unit testing of the permissioning system.

File-Level Changes

Change Details Files
Removal of ObjectPermissionChecker monkey patch
  • Removed weakref import and _cache WeakKeyDictionary
  • Deleted custom ObjectPermissionChecker class implementation
  • Removed override of guardian's ObjectPermissionChecker
strawberry_django/integrations/guardian.py
Clean up of unused imports and type annotations
  • Removed import for Group model
  • Removed import for guardian backends
  • Removed import for original ObjectPermissionChecker
  • Removed Optional from type annotations
strawberry_django/integrations/guardian.py

Sequence Diagram

No sequence diagram generated.


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 - here's some feedback:

Overall Comments:

  • Could you provide some benchmark results or performance data to confirm that removing this optimization doesn't significantly increase the number of database queries in typical use cases?
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.75%. Comparing base (93b1bf4) to head (18848ee).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #631      +/-   ##
==========================================
- Coverage   88.79%   88.75%   -0.05%     
==========================================
  Files          41       41              
  Lines        3605     3592      -13     
==========================================
- Hits         3201     3188      -13     
  Misses        404      404              
Flag Coverage Δ
88.75% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@bellini666 bellini666 merged commit 736f2a7 into main Sep 24, 2024
22 checks passed
@bellini666 bellini666 deleted the remove_guardian_monkey_patch branch September 24, 2024 22:05
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.

2 participants