Merge pull request #2478 from brandoncazander/version-3.1

Clone the versioning_scheme when necessary. Fixes #2477
This commit is contained in:
José Padilla 2015-01-27 21:21:42 -04:00
commit 8f33e39f62
2 changed files with 18 additions and 1 deletions

View File

@ -109,6 +109,8 @@ def clone_request(request, method):
ret.accepted_media_type = request.accepted_media_type ret.accepted_media_type = request.accepted_media_type
if hasattr(request, 'version'): if hasattr(request, 'version'):
ret.version = request.version ret.version = request.version
if hasattr(request, 'versioning_scheme'):
ret.versioning_scheme = request.versioning_scheme
return ret return ret

View File

@ -1,5 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from rest_framework import exceptions, serializers, status, views from rest_framework import exceptions, serializers, status, views, versioning
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.renderers import BrowsableAPIRenderer from rest_framework.renderers import BrowsableAPIRenderer
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
@ -183,3 +183,18 @@ class TestMetadata:
view = ExampleView.as_view() view = ExampleView.as_view()
view(request=request) view(request=request)
def test_bug_2477_clone_request(self):
class ExampleView(views.APIView):
renderer_classes = (BrowsableAPIRenderer,)
def post(self, request):
pass
def get_serializer(self):
assert hasattr(self.request, 'versioning_scheme')
return serializers.Serializer()
scheme = versioning.QueryParameterVersioning
view = ExampleView.as_view(versioning_class=scheme)
view(request=request)