Django-rest-framework: 'NoneType' object has no attribute 'user' while accessing docs api

Created on 3 Jun 2017  Â·  11Comments  Â·  Source: encode/django-rest-framework

Checklist

  • [x] I have verified that that issue exists against the master branch of Django REST framework.
  • [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [x] This is not a usage question. (Those should be directed to the discussion group instead.)
  • [x] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • [] I have reduced the issue to the simplest possible case.
  • [] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

  1. create api viewset and try to access self.request.
  2. integrate docs endpoint as described in docs
  3. hit the docs endpoint in browser

    Expected behavior

API docs page should render

Actual behavior

Error 'NoneType' object has no attribute 'user'
traceback
self.request is None

Documentation Interactive API Documentation

Most helpful comment

I experience the same issue as @scriptonist. I'm not sure though if it is related to the original issue...


This is what I have found so far:

  1. When I'm logged in, everything works as expected.
  2. When I'm NOT logged in, the error 'NoneType' object has no attribute 'items' appears.

I managed to trace it to the following setting:
python REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), }
If I comment out the line: 'rest_framework.permissions.IsAuthenticated',, the docs endpoint works as expected.

All 11 comments

This issue also persists in another variation.
'NoneType' object has no attribute 'items'

I experience the same issue as @scriptonist. I'm not sure though if it is related to the original issue...


This is what I have found so far:

  1. When I'm logged in, everything works as expected.
  2. When I'm NOT logged in, the error 'NoneType' object has no attribute 'items' appears.

I managed to trace it to the following setting:
python REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), }
If I comment out the line: 'rest_framework.permissions.IsAuthenticated',, the docs endpoint works as expected.

Recently switched to 3.6 to try to implement the new coreapi goodnesses. I am experiencing the same issues, more generally I think it would be nice to have some technical infos about how the documentation is generated.

I customized a lot my viewsets to avoid redundant code (dynamic serializers fields and class, dynamic querysets,) using the request context (type of user, action, etc). And it seems these info are not available when generating the doc.

My assumption is DRF is cycling through all available actions but without request, but this would help to get more info about how this is done in the next release.

@Kiougar still not working for me

I have restful version 3.6.3
and get error 'NoneType' object has no attribute 'items'
link to code where error appears {% for link_key, link in section.links|items %}

Same issue. Latest DRF, Python 3.6.1.

My Viewsets are accessing self.request.user. Even when I'm logged in, docs page raises an error:
'NoneType' object has no attribute 'user'

There's no point in adding additional comments that you face the issue. It's been reported already.
The next steps here would be to add a failing test case to DRF's test suite and then work on a fix.
Any volunteer around ?

I can confirm the error exists for include_docs_urls(Public=True) on DRF version 3.6.3 when not authenticated and IsAuthenticated permissions are set

3.6.4 fixed it on my side.

This is basically the same issue as #5142.

  • You need to be able to handle request=None — since the default get_docs_view sets public=True
  • Once we document this a bit better you'll be able to replace include_docs_urls to configure the view as you want it.

(I'll leave this open just for now to make sure we capture the different aspects here.)

Still persists,
Python : 3.6
Django 2.0
DRF 3.8.2

On Accessing /docs/ as described here , faced the same above issue.

Was this page helpful?
0 / 5 - 0 ratings