Skip to content

fix: Pass request to Site.objects.get_current #8298

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Jul 29, 2025

Description

Related resources

Checklist

Summary by Sourcery

Forward request context to site resolution for consistent behavior and deprecate implicit usage

Enhancements:

  • Extend get_current_site to accept an HttpRequest and emit a warning when none is provided
  • Update all internal calls to get_current_site to pass the request parameter explicitly
  • Add return type annotation for get_language_from_request

Copy link
Contributor

sourcery-ai bot commented Jul 29, 2025

Reviewer's Guide

Extended get_current_site to require an HttpRequest argument (with a deprecation warning when omitted), added a return type annotation for get_language_from_request, and refactored all callers (admin, toolbar, decorators, i18n, page utilities, views, wizards, and menus) to pass the request object.

Sequence diagram for get_current_site usage with request parameter

sequenceDiagram
    participant Caller
    participant get_current_site
    participant SiteManager as Site.objects
    Caller->>get_current_site: get_current_site(request)
    get_current_site->>SiteManager: get_current(request)
    SiteManager-->>get_current_site: Site instance
    get_current_site-->>Caller: Site instance
Loading

Class diagram for updated get_current_site utility function

classDiagram
    class get_current_site {
        +Site get_current_site(request: Optional[HttpRequest])
    }
    class Site {
        +Site get_current(request: Optional[HttpRequest])
    }
    get_current_site --> Site : calls get_current(request)
Loading

File-Level Changes

Change Details Files
Extend get_current_site API to accept an HttpRequest and warn on missing argument
  • Changed signature to def get_current_site(request: Optional[HttpRequest])
  • Added DeprecationWarning when request is None
  • Forwarded request to Site.objects.get_current(request)
cms/utils/__init__.py
Add return type annotation to get_language_from_request
  • Annotated function signature with -> str
cms/utils/__init__.py
Propagate request parameter in all get_current_site callers
  • Refactored admin modules to pass request
  • Updated toolbar, decorators and utility functions to pass request
  • Adjusted i18n, page utilities and view functions to include request
  • Modified wizard dispatch and menu tags/utils to use request
cms/admin/pageadmin.py
cms/admin/placeholderadmin.py
cms/toolbar_base.py
cms/utils/decorators.py
cms/utils/i18n.py
cms/utils/page.py
cms/views.py
cms/wizards/views.py
menus/templatetags/menu_tags.py
menus/utils.py

Possibly linked issues

  • Cross Domain Request Error  #1: The PR passes the request object to site-related functions, resolving the AttributeError when previewing pages from different sites.
  • Error while manage.py migrate #123: PR passes request to get_current_site, resolving multi-site 404 from incorrect site filtering.
  • #0: PR passes request to Site.objects.get_current, resolving incorrect URL prefixes across sites by ensuring correct site context.

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.57%. Comparing base (ee2d973) to head (2481378).

Files with missing lines Patch % Lines
cms/admin/pageadmin.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8298   +/-   ##
=======================================
  Coverage   89.57%   89.57%           
=======================================
  Files         129      129           
  Lines       12691    12694    +3     
=======================================
+ Hits        11368    11371    +3     
  Misses       1323     1323           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant