Skip to content

Fixes BrowsableAPIRenderer for usage with ListSerializer. #7530

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

Merged

Conversation

NiyazNz
Copy link
Contributor

@NiyazNz NiyazNz commented Sep 10, 2020

When using ListSerializer as viewset serializer_class rendering of view in BrowsableAPI fails with:

Internal Server Error: /api/snippets/
Traceback (most recent call last):
  File "/home/nz/.local/lib/virtualenvs/django-rest-framework-demo/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nz/.local/lib/virtualenvs/django-rest-framework-demo/lib/python3.11/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "/home/nz/.local/lib/virtualenvs/django-rest-framework-demo/lib/python3.11/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nz/dev/.oss/django-rest-framework/rest_framework/response.py", line 74, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nz/dev/.oss/django-rest-framework/rest_framework/renderers.py", line 725, in render
    context = self.get_context(data, accepted_media_type, renderer_context)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nz/dev/.oss/django-rest-framework/rest_framework/renderers.py", line 656, in get_context
    raw_data_post_form = self.get_raw_data_form(data, view, 'POST', request)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nz/dev/.oss/django-rest-framework/rest_framework/renderers.py", line 564, in get_raw_data_form
    for name, field in serializer.fields.items():
                       ^^^^^^^^^^^^^^^^^
AttributeError: 'MultipleSnippetSerializer' object has no attribute 'fields'
[12/Jun/2023 08:41:53] "GET /api/snippets/ HTTP/1.1" 500 97475

BrowsableAPIRenderer cannot render multiple objects in HTML form and should render list example in Raw data.

This PR fixes the issue described above by rendering list of items in Raw data tab and not rendering HTML data tab while ListSerializer is used for viewset serializer_class.
image

@stale
Copy link

stale bot commented May 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 1, 2022
@NiyazNz NiyazNz force-pushed the fix-browsable-api-list-serializer-rendering branch from 33df4bb to ff1778e Compare May 3, 2022 15:26
@stale stale bot removed the stale label May 3, 2022
@stale
Copy link

stale bot commented Jul 10, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 10, 2022
@stale stale bot closed this Dec 24, 2022
@auvipy auvipy reopened this Dec 24, 2022
@stale stale bot removed the stale label Dec 24, 2022
@stale
Copy link

stale bot commented Apr 2, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2023
@auvipy auvipy removed the stale label Apr 3, 2023
@stale
Copy link

stale bot commented Jun 10, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 10, 2023
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please rebase to fix the failing CI?

@stale stale bot removed the stale label Jun 10, 2023
Renders list of items in raw_data_form and does not renders form in
template while using with `ListSerializer` (`many=True`).
@NiyazNz NiyazNz force-pushed the fix-browsable-api-list-serializer-rendering branch from ff1778e to 837360e Compare June 12, 2023 08:45
@NiyazNz NiyazNz requested a review from auvipy June 12, 2023 09:16
@auvipy auvipy added this to the 3.15 milestone Jun 12, 2023
@auvipy auvipy merged commit 02d9bfc into encode:master Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants