django-rest-framework-xml
django-rest-framework-xml copied to clipboard
Possible ValuesQuerySet iteration issue
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?