Skip to content

Possible ValuesQuerySet iteration issue #33

@GertBurger

Description

@GertBurger

Hi

I noticed one of our endpoints breaks when outputting as xml but works fine when using the DRF json renderer.

It outputs something like this:

<root> *a long string ending in* , '...(remaining elements truncated)...']</root>

With an endpoint similar to this:

@api_view()
def myendpoint(request):
    return Response(MyModel.objects.values('field1', 'field2'))

Wrapping the ValuesQuerySet in a list() call fixes the problem.

The DRF docs mention that Response() objects should only be given Python primitives so I understand that this specific usage may not (and possibly should not) be supported.

It is however unexpected that the behaviour differs from DRF's standard JSON renderer which iterates correctly over ValuesQuerySets.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions