[Django] #36018: Sites.objects.get_current() will always return the settings.SITE_ID, even when the optional request is passed

4 views
Skip to first unread message

Django

unread,
Dec 16, 2024, 3:24:37 PM12/16/24
to django-...@googlegroups.com
#36018: Sites.objects.get_current() will always return the settings.SITE_ID, even
when the optional request is passed
-------------------------+-----------------------------------------
Reporter: devo-wm | Type: Bug
Status: new | Component: contrib.sites
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------+-----------------------------------------
It looks like if you've set the SITE_ID in your settings, the conditional
in get_current() will always return that site id, even if you pass the
optional request.

We thought that perhaps un-setting the SITE_ID would resolve this, but
these seems to counter the steps involved when enabling and configuring
the sites framework:
https://docs.djangoproject.com/en/5.1/ref/contrib/sites/#enabling-the-
sites-framework

The simple fix seems to be switching the order of the conditional in that
method, thereby always checking the optional request parameter first.
--
Ticket URL: <https://code.djangoproject.com/ticket/36018>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 16, 2024, 5:37:38 PM12/16/24
to django-...@googlegroups.com
#36018: Sites.objects.get_current() will always return the settings.SITE_ID, even
when the optional request is passed
-------------------------------+--------------------------------------
Reporter: DeVon Jackson | Owner: (none)
Type: Bug | Status: closed
Component: contrib.sites | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tim Graham):

* resolution: => invalid
* status: new => closed

Comment:

You're proposing a change in
[https://docs.djangoproject.com/en/dev/ref/contrib/sites/#django.contrib.sites.shortcuts.get_current_site
the documented behavior]:

"A function that checks if django.contrib.sites is installed and returns
either the current Site object or a RequestSite object based on the
request. It looks up the current site based on request.get_host() if the
SITE_ID setting is not defined."

Changing it would be backward incompatible. If you want to argue for a
behavior change, you should research why the current behavior exists and
explain the rationale for your proposal on
[https://forum.djangoproject.com/c/internals/5 the Django forum].
--
Ticket URL: <https://code.djangoproject.com/ticket/36018#comment:1>
Reply all
Reply to author
Forward
0 new messages