Skip to content

Conversation

@czosel
Copy link
Contributor

@czosel czosel commented Jun 5, 2019

(This is actually more an issue instead of a PR, but since I have a failing test, I figured I'd post this as a PR anyway.)

When meta is used as attribute name, PATCH requests are failing because the attribute's value is used in a code path which is supposed to handle the top-level meta property.

Request body (taken from the test case):

        request_data = {
            'data': {
                'type': 'comments',
                'id': self.second_comment.id,
                'attributes': {
                    'meta': "test"
                }
            }
        }

Exception:

Traceback (most recent call last):
  File "/home/christian/.pyenv/versions/3.6.7/envs/drf-json-api/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/christian/.pyenv/versions/3.6.7/envs/drf-json-api/lib/python3.6/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/christian/.pyenv/versions/3.6.7/envs/drf-json-api/lib/python3.6/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/home/christian/.pyenv/versions/3.6.7/envs/drf-json-api/lib/python3.6/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/home/christian/.pyenv/versions/3.6.7/envs/drf-json-api/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
  File "/home/christian/dev/django-rest-framework-json-api/rest_framework_json_api/renderers.py", line 572, in render
    json_api_meta.update(self.extract_root_meta(serializer, serializer_data))
AttributeError: 'str' object has no attribute 'update'

I didn't find any note that meta should not be used as attribute name. If that actually is advised, it would be great to check the models and throw an Error if a model/serializer with a meta property is found.

@sliverc
Copy link
Member

sliverc commented Jun 6, 2019

According to the specification only name type and id are not allowed but meta should be. See https://jsonapi.org/format/#document-resource-object-fields

This might be a bit tricky to implement though.

@sliverc
Copy link
Member

sliverc commented Jun 6, 2019

@czosel
Feel free to work on it if you find time.

@sliverc
Copy link
Member

sliverc commented Oct 2, 2019

As this is an unfinished PR I have created an issue #710 referencing this PR as example.

Closing this PR but contributions are still welcome 😄

@sliverc sliverc closed this Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants