Opened 44 hours ago

Closed 41 hours ago

#36018 closed Bug (invalid)

Sites.objects.get_current() will always return the settings.SITE_ID, even when the optional request is passed

Reported by: DeVon Jackson Owned by:
Component: contrib.sites Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Change History (1)

comment:1 by Tim Graham, 41 hours ago

Resolution: invalid
Status: newclosed

You're proposing a change in 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 the Django forum.

Note: See TracTickets for help on using tickets.
Back to Top