On 12/6/23 11:00, Jered Floyd wrote:
These errors are generated to me as the admin, and in the elided environment section SITE_ID is indeed 0, but I'm at a loss to imagine why this happens only sometimes!
For me, on a test installation with SITE_ID = 0, this only occurs at https://example.com/accounts/social/connections/
Other URLs such as https://example.com/accounts/password/change/ and https://example.com/accounts/email/ do not throw this exception.
Here's the code:
def get_current(self, request=None):
"""
Return the current Site based on the SITE_ID in the project's
settings.
If SITE_ID isn't defined, return the site with domain matching
request.get_host(). The ``Site`` object is cached the first
time it's
retrieved from the database.
"""
from django.conf import settings
if getattr(settings, "SITE_ID", ""):
site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)
raise ImproperlyConfigured(
'You\'re using the Django "sites framework" without having '
"set the SITE_ID setting. Create a site in your database and "
"set the SITE_ID setting or pass a request to "
"Site.objects.get_current() to fix this error."
)
I tried patching it from
if getattr(settings, "SITE_ID", ""):
to
if getattr(settings, "SITE_ID", None) is not None:
but that's even worse. It throws a bunch of "django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist." errors.
Somehow, get_current is being called without a request object in the cases where it fails.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan