Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29296 closed Bug (fixed)

admindocs ViewIndexView crashes if a syndication Feed (or something without __qualname__) is configured

Reported by: Paul Donohue Owned by: nobody
Component: contrib.admindocs Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Paul Donohue)

If a Feed (https://docs.djangoproject.com/en/2.0/ref/contrib/syndication/) is configured anywhere in the project, then /admin/doc/views/ (https://docs.djangoproject.com/en/2.0/ref/contrib/admin/admindocs/) crashes with AttributeError: 'GlobalFeed' object has no attribute '__qualname__'

The problem is that Feed is a callable object (https://github.com/django/django/blob/master/django/contrib/syndication/views.py#L34) and the documentation uses that class directly as a View (path('latest/feed/', LatestEntriesFeed()),), but admindocs assumes that all views are functions and it does not work properly with a callable object (https://github.com/django/django/blob/master/django/contrib/admindocs/views.py#L130).

In Django 1.11 and earlier, admindocs supported callable objects on Python 2 because it fell back to view.__class__.__name__, but it appears that the Python 3 code in admindocs has not supported this since it was added in https://github.com/django/django/commit/ae0f55eb491255217d6df31296ec8102007224a6 (https://code.djangoproject.com/ticket/27018).

As a work-around, __qualname__ can be manually defined on Feed objects:

class MyFeed(Feed):
    def __init__(self):
        super().__init__()
        self.__qualname__ = self.__class__.__name__

Without knowing Django's opinion of the use of callable objects as views, I don't know the appropriate way to fix this: Should admindocs support callable objects as views, or should Feed not use a callable object as a view?

Change History (9)

comment:1 by Paul Donohue, 7 years ago

Description: modified (diff)

comment:2 by Paul Donohue, 7 years ago

Description: modified (diff)

comment:3 by Paul Donohue, 7 years ago

Description: modified (diff)

comment:4 by Tim Graham, 7 years ago

Component: Uncategorizedcontrib.admindocs
Summary: admindocs crash if a Feed is configuredadmindocs ViewIndexView crashes if a syndication Feed (or something without __qualname__) is configured
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

I think admindocs must be changed not to assume __qualname__ since I don't think sitemaps could be changed without being backwards incompatible.

comment:5 by Carlton Gibson, 7 years ago

Has patch: set

comment:6 by Carlton Gibson, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 33a0b7ac:

Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.

comment:8 by Tim Graham <timograham@…>, 7 years ago

In 1ed31efb:

[2.0.x] Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.

Backport of 33a0b7ac815588ed92dca215e153390af8bdbdda from master

comment:9 by Tim Graham <timograham@…>, 7 years ago

In 979253f:

[1.11.x] Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.

Backport of 33a0b7ac815588ed92dca215e153390af8bdbdda from master

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