Skip to content

AttributeError: 'NoneType' object has no attribute 'get' #275

Closed
@z0al

Description

@z0al

Hi, there

Since yesterday, I'm stuck on this error in my test script:

Creating test database for alias 'default'...
E
======================================================================
ERROR: test_create_account (api.accounts.tests.test_crud.AccountTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/api/accounts/tests/test_crud.py", line 22, in test_create_account
    response = self.client.post(url, data)
  File "/usr/local/lib/python3.5/site-packages/rest_framework/test.py", line 169, in post
    path, data=data, format=format, content_type=content_type, **extra)
  File "/usr/local/lib/python3.5/site-packages/rest_framework/test.py", line 90, in post
    data, content_type = self._encode_data(data, format, content_type)
  File "/usr/local/lib/python3.5/site-packages/rest_framework/test.py", line 65, in _encode_data
    ret = renderer.render(data)
  File "/usr/local/lib/python3.5/site-packages/rest_framework_json_api/renderers.py", line 419, in render
    view = renderer_context.get("view", None)
AttributeError: 'NoneType' object has no attribute 'get'

----------------------------------------------------------------------
Ran 1 test in 0.019s

FAILED (errors=1)
Destroying test database for alias 'default'...

Particularly, this is the line of my code causing the error:

response = self.client.post(url, data)

And this is the line of your code that responsible of the error

view = renderer_context.get("view", None)

Simply because renderer_context is None

All my test was passing before switching to this library (using default DRF renders)

Here is my configurations:

REST_FRAMEWORK = {
    'PAGE_SIZE': 5,
    'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
    'DEFAULT_PAGINATION_CLASS':
        'rest_framework_json_api.pagination.PageNumberPagination',
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',

    'TEST_REQUEST_RENDERER_CLASSES':(
        'rest_framework_json_api.renderers.JSONRenderer',
    ),
    'TEST_REQUEST_PARSER_CLASSES':(
        'rest_framework_json_api.parsers.JSONParser',
    ),
    'TEST_REQUEST_DEFAULT_FORMAT' : 'vnd.api+json',
}

Am I doing something wrong ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions