﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33420	Cannot import name RequestSite from partially initialized module.	Raphaël Hertzog	nobody	"In a website that has always been working fine, I have started to get occasional errors in codepath that use contrib.syndication.views:

{{{
File ""/usr/lib/python3/dist-packages/django/core/handlers/exception.py"" in inner
  34.             response = get_response(request)

File ""/usr/lib/python3/dist-packages/django/core/handlers/base.py"" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File ""/usr/lib/python3/dist-packages/django/core/handlers/base.py"" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File ""/usr/lib/python3/dist-packages/django/contrib/syndication/views.py"" in __call__
  39.         feedgen = self.get_feed(obj, request)

File ""/usr/lib/python3/dist-packages/django/contrib/syndication/views.py"" in get_feed
  127.         current_site = get_current_site(request)

File ""/usr/lib/python3/dist-packages/django/contrib/sites/shortcuts.py"" in get_current_site
  15.         from .requests import RequestSite

Exception Type: ImportError at /pkg/gdb/rss
Exception Value: cannot import name 'RequestSite' from partially initialized module 'django.contrib.sites.requests' (most likely due to a circular import)
(/usr/lib/python3/dist-packages/django/contrib/sites/requests.py)

}}}

Note that in the Django configuration, I do not enable the django.contrib.sites application. This seems to be in line with the django.contrib.syndication doc saying that if you don't have the django.contrib.sites application you get a RequestSite object instead.

FWIW the view is here: https://salsa.debian.org/qa/distro-tracker/-/blob/master/distro_tracker/core/news_feed.py#L37
And this is about https://tracker.debian.org

This is reproduced with Django 2.2.25 (Debian package python3-django 2:2.2.25-1~deb11u1)  and I know it's relatively old. But I find it weird that this problem started to appear recently (or at least get more frequent) since the website has been upgraded to run on Debian 11 instead of Debian 10 (the Django major version has not changed, but the Python version went to 3.9 and the dependencies have been upgraded too). Or it might be related to some recent updates within 2.2.x but that seems unlikely since it's only security updates at this point.

As a wild guess, the underlying reason is more likely to be related to changes in Python 3.9 import logic."	Bug	closed	contrib.syndication	2.2	Normal	fixed			Unreviewed	0	0	0	0	0	0
