[Django] #27018: Admin view in admindocs are not accessible

31 views
Skip to first unread message

Django

unread,
Aug 4, 2016, 12:28:14 PM8/4/16
to django-...@googlegroups.com
#27018: Admin view in admindocs are not accessible
---------------------------------------------+------------------------
Reporter: MarkusH | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admindocs | Version: 1.10
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 |
---------------------------------------------+------------------------
When using `django.contrib.admindocs` the views under the `admin`
namespace are not available. With the exception of
`/admin/<app_label>/<model>/<var>/` and
`/admin/r/<content_type_id>/<object_id>/`.

Django 1.9.8 returns a HTTP 404 while 1.10 raises an attribute error. It
appears that only views that are defined as methods on a class are an
issue.

This is likely related to #24931 and #23601.

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

Django

unread,
Aug 4, 2016, 3:15:19 PM8/4/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: Bug | Status: new
Component: contrib.admindocs | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by timgraham):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Bisected the change in 1.10 to 31a789f646d0d9af3e8464f2f9a06aa018df5f90.

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

Django

unread,
Aug 6, 2016, 1:43:04 PM8/6/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by helenst):

* owner: nobody => helenst
* status: new => assigned


Comment:

I'll have a look at this.

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

Django

unread,
Aug 12, 2016, 8:31:01 AM8/12/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by helenst):

The problem is that the callbacks for these views are methods on classes.

For those two links that do work:
`/admin/r/<content_type_id>/<object_id>/` view function is
`django.contrib.contenttypes.views.shortcut`
`/admin/<app_label>/<model>/<var>/` view function is
`django.views.generic.base.RedirectView`
and both of those exist and can be resolved in `ViewDetailView` so they're
fine.

However for `/admin/` the view function is shown as
`django.contrib.admin.sites.index` which does not exist. It's
`django.contrib.admin.sites.AdminSite.index` (or
`django.contrib.admin.sites.site.index` since the sites module exposes an
instance of AdminSite). This means the view function is insufficiently
specified on the URL for the view detail.

This is true for all the others that are crashing.

Next step will be to write some failing tests.

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

Django

unread,
Aug 12, 2016, 2:14:50 PM8/12/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by helenst):

I'm working on branch https://github.com/helenst/django/tree/ticket_27018

Have written tests for the detail and index views.

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

Django

unread,
Aug 18, 2016, 12:10:55 PM8/18/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by helenst):

I've fixed this but it's a Python 3 only fix due to the use of
`__qualname__` to find out which class the view comes from and therefore
generate the correct URL.

There are ways to emulate `__qualname__` in py2, but kind of hacky. I see
in migrations/serializers.py qualname is also used and a message generated
for py2 users. Is a Python 3 only solution acceptable here? In Python 2 it
will continue to just not work (and could be tidied up to raise a 404
rather than an error).

I am not sure what is the best thing here, so some input would be good!
All is pushed to the branch linked above.

There is also the issue of ensuring the tests pass (i.e. I have added test
cases but they only pass for python 3).

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

Django

unread,
Aug 18, 2016, 1:39:03 PM8/18/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by timgraham):

I don't mind if the fix is Python 3 only. Python 2 raising a 404 as
happened in older versions of Django would be okay.

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:6>

Django

unread,
Aug 18, 2016, 6:32:40 PM8/18/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by MarkusH):

Awesome Helen! A Python 3 solution would be fine and more than we have now
:)

For the tests I'd either go with

{{{#!python
if six.PY2:
validate_stuff_py2()
else:
validate_stuff_py3()
}}}

or

{{{#!python
@unittest.skipIf(six.PY2, "Only supported for Python 3")
def test_foo_py3(self):
validate_stuff_py3()

@unittest.skipIf(six.PY3, "Only supported for Python 2")
def test_foo_py2(self):
validate_stuff_py2()
}}}

The first might be easier to maintain (for the time where we still have
general Python 2 support in Django).

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:7>

Django

unread,
Aug 19, 2016, 12:28:16 PM8/19/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

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

Comment (by helenst):

PR: https://github.com/django/django/pull/7127

Tests pass on 2.7 and 3.5. I have also added a note in the documentation
about this.

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:8>

Django

unread,
Aug 19, 2016, 5:39:26 PM8/19/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

Left some comments for improvement.

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:9>

Django

unread,
Aug 20, 2016, 9:02:20 AM8/20/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: assigned
Component: contrib.admindocs | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by helenst):

* needs_better_patch: 1 => 0


Comment:

Hi Tim, thank you for the review! I have made improvements as suggested.

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:10>

Django

unread,
Aug 20, 2016, 10:02:22 AM8/20/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: closed
Component: contrib.admindocs | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"bc1e2d8e8edde6cc7d2657c68242a13ee65a15b8" bc1e2d8e]:
{{{
#!CommitTicketReference repository=""
revision="bc1e2d8e8edde6cc7d2657c68242a13ee65a15b8"
Fixed #27018 -- Fixed admindocs crash with a view in a class.

Generated correct admindocs URLs on Python 3. URLs generate 404s on
Python 2, as in older versions of Django.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:11>

Django

unread,
Aug 20, 2016, 10:14:48 AM8/20/16
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-----------------------------------+------------------------------------
Reporter: MarkusH | Owner: helenst
Type: Bug | Status: closed
Component: contrib.admindocs | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"ae0f55eb491255217d6df31296ec8102007224a6" ae0f55e]:
{{{
#!CommitTicketReference repository=""
revision="ae0f55eb491255217d6df31296ec8102007224a6"
[1.10.x] Fixed #27018 -- Fixed admindocs crash with a view in a class.

Generated correct admindocs URLs on Python 3. URLs generate 404s on
Python 2, as in older versions of Django.

Backport of bc1e2d8e8edde6cc7d2657c68242a13ee65a15b8 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:12>

Django

unread,
Apr 6, 2018, 9:35:49 AM4/6/18
to django-...@googlegroups.com
#27018: Admin views in admindocs crash with AttributeError
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: Helen
| Sherwood-Taylor
Type: Bug | Status: closed
Component: contrib.admindocs | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Paul Donohue):

This seems to have introduced a bug:
https://code.djangoproject.com/ticket/29296

--
Ticket URL: <https://code.djangoproject.com/ticket/27018#comment:13>

Reply all
Reply to author
Forward
0 new messages