#29296: admindocs crash if a Feed is configured -------------------------------+-------------------------------------- Reporter: Paul Donohue | Owner: nobody Type: Uncategorized | Status: new Component: Uncategorized | Version: 2.0 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Description changed by Paul Donohue:
Old description: > 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 by falling 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__ = '__call__' > }}} > > 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? New description: 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 used `view.__name__` instead of `view.__qualname__`, 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__ = '__call__' }}} 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? -- -- Ticket URL: <https://code.djangoproject.com/ticket/29296#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.8b26f92a919beee876401e766cc29f63%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.