Skip to content
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

AdminRenderer does not work without pagination being enabled #3275

Closed
parisk opened this issue Aug 15, 2015 · 4 comments
Closed

AdminRenderer does not work without pagination being enabled #3275

parisk opened this issue Aug 15, 2015 · 4 comments
Labels
Milestone

Comments

@parisk
Copy link

parisk commented Aug 15, 2015

Attempting to load a view rendered with AdminRenderer results to server error, if no pagination class has been set up.

I assume that this should either be fixed or documented at http://www.django-rest-framework.org/api-guide/renderers/#adminrenderer.

@tomchristie
Copy link
Member

What's the error?

@parisk
Copy link
Author

parisk commented Aug 19, 2015

It's a TypeError (list indices must be integers, not unicode).

Screenshot

screenshot 2015-08-19 15 12 17

@ugurunver
Copy link

Same error here. I use release 3.2.2.

It occured when i give a list to a Response object as data.
(Actually not just list, all non-dict types cause error at this point, i think)

https://github.com/tomchristie/django-rest-framework/blob/ed65db367ad9cd9d2fbb4da2ef8093b9a93a4fd6/rest_framework/renderers.py#L740

      paginator = getattr(context['view'], 'paginator', None)
      if (paginator is not None and data is not None):
          try:
              results = paginator.get_results(data)
          except KeyError:
              results = data
      else:
          results = data

It handles just KeyError and it is only for dict type data.
And paginator.get_results is:
https://github.com/tomchristie/django-rest-framework/blob/ed65db367ad9cd9d2fbb4da2ef8093b9a93a4fd6/rest_framework/pagination.py#L161

def get_results(self, data):
    return data['results']

So, when data is a list type object, it makes like [1,2,3]['results'].
I think one solution may be:

def get_results(self, data):
    if isinstance(data, list):
        return data
    return data['results']

@tomchristie
Copy link
Member

Thanks for raising this, folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants