Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33420 closed Bug (fixed)

Cannot import name RequestSite from partially initialized module.

Reported by: Raphaël Hertzog Owned by: nobody
Component: contrib.syndication Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: fixed
Status: newclosed
Type: UncategorizedBug

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 discussion in PR.

comment:2 by Mariusz Felisiak, 3 years ago

Summary: cannot import name 'RequestSite' from partially initialized module 'django.contrib.sites.requests' (most likely due to a circular import)Cannot import name RequestSite from partially initialized module.

comment:3 by Claude Paroz, 3 years ago

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

in reply to:  3 comment:4 by Raphaël Hertzog, 3 years ago

Replying to 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.

comment:5 by Claude Paroz, 3 years ago

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

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