Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Patch request with "meta" attribute fails #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
czosel wants to merge 1 commit into django-json-api:master from czosel:meta-patch-attribute

Conversation

Copy link
Contributor

@czosel czosel commented Jun 5, 2019
edited
Loading

(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.

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.

Copy link
Member

sliverc commented Jun 6, 2019

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

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /