[Django] #33420: cannot import name 'RequestSite' from partially initialized module 'django.contrib.sites.requests' (most likely due to a circular import)

23 views
Skip to first unread message

Django

unread,
Jan 7, 2022, 3:21:09 AM1/7/22
to django-...@googlegroups.com
#33420: cannot import name 'RequestSite' from partially initialized module
'django.contrib.sites.requests' (most likely due to a circular import)
-----------------------------------------------+------------------------
Reporter: Raphaël Hertzog | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.syndication | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33420>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 7, 2022, 3:50:16 AM1/7/22
to django-...@googlegroups.com
#33420: cannot import name 'RequestSite' from partially initialized module
'django.contrib.sites.requests' (most likely due to a circular import)
-------------------------------------+-------------------------------------

Reporter: Raphaël Hertzog | Owner: nobody
Type: Bug | Status: closed
Component: contrib.syndication | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* type: Uncategorized => Bug
* resolution: => fixed


Comment:

Thanks for the report. This should be already fixed by
78163d1ac4407d59bfc5fdf1f84f2dbbb2ed3443 on the current `main` branch.
Unfortunately, we don't know how to reproduce this at will, see a
[https://github.com/django/django/pull/15077 discussion in PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/33420#comment:1>

Django

unread,
Jan 7, 2022, 3:51:17 AM1/7/22
to django-...@googlegroups.com
#33420: Cannot import name RequestSite from partially initialized module.
-------------------------------------+-------------------------------------

Reporter: Raphaël Hertzog | Owner: nobody
Type: Bug | Status: closed
Component: contrib.syndication | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/33420#comment:2>

Django

unread,
Jan 7, 2022, 4:10:56 AM1/7/22
to django-...@googlegroups.com
#33420: Cannot import name RequestSite from partially initialized module.
-------------------------------------+-------------------------------------

Reporter: Raphaël Hertzog | Owner: nobody
Type: Bug | Status: closed
Component: contrib.syndication | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

I'm also surprised that was not reported more often. Could this be related
to the Debian-packaged Python 3.9 version?

--
Ticket URL: <https://code.djangoproject.com/ticket/33420#comment:3>

Django

unread,
Jan 7, 2022, 4:19:53 AM1/7/22
to django-...@googlegroups.com
#33420: Cannot import name RequestSite from partially initialized module.
-------------------------------------+-------------------------------------

Reporter: Raphaël Hertzog | Owner: nobody
Type: Bug | Status: closed
Component: contrib.syndication | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Raphaël Hertzog):

Replying to [comment:3 Claude Paroz]:


> I'm also surprised that was not reported more often. Could this be
related to the Debian-packaged Python 3.9 version?

Did you also reproduce it on a Debian 11 system? Debian 11 has Python
3.9.2 so not the latest 3.9.x. Apart from this, I'm not sure that the
Debian-packaged version has any meaninful difference compared to upstream.

But I'm not even sure that it's strictly related to the Python version.
IIRC I got a similar error on another system running Django 2.2.24 on
Debian 10 with Python 3.7.3.

--
Ticket URL: <https://code.djangoproject.com/ticket/33420#comment:4>

Django

unread,
Jan 7, 2022, 6:36:28 AM1/7/22
to django-...@googlegroups.com
#33420: Cannot import name RequestSite from partially initialized module.
-------------------------------------+-------------------------------------

Reporter: Raphaël Hertzog | Owner: nobody
Type: Bug | Status: closed
Component: contrib.syndication | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Yes, I'm now using Debian 11 everywhere with packaged Python. I don't
remember seeing such errors when I was on Debian 10.

--
Ticket URL: <https://code.djangoproject.com/ticket/33420#comment:5>

Reply all
Reply to author
Forward
0 new messages