Browse Source

py3(drf): bump djangorestframework to 3.4.x (#14974)

josh 5 years ago
parent
commit
d1e9afc17f

+ 1 - 1
requirements-base.txt

@@ -13,7 +13,7 @@ django-jsonfield>=0.9.13,<0.9.14
 django-picklefield>=0.3.0,<1.1.0
 django-sudo>=2.1.0,<3.0.0
 Django>=1.8,<1.9
-djangorestframework==3.2.5
+djangorestframework==3.4.7
 email-reply-parser>=0.2.0,<0.3.0
 enum34>=1.1.6,<1.2.0
 functools32>=3.2.3,<3.3

+ 1 - 4
src/sentry/api/base.py

@@ -13,8 +13,6 @@ from enum import Enum
 from pytz import utc
 from rest_framework.authentication import SessionAuthentication
 from rest_framework.exceptions import ParseError
-from rest_framework.parsers import JSONParser
-from rest_framework.renderers import JSONRenderer
 from rest_framework.response import Response
 from rest_framework.views import APIView
 from simplejson import JSONDecodeError
@@ -60,9 +58,8 @@ class DocSection(Enum):
 
 
 class Endpoint(APIView):
+    # Note: the available renderer and parser classes can be found in conf/server.py.
     authentication_classes = DEFAULT_AUTHENTICATION
-    renderer_classes = (JSONRenderer,)
-    parser_classes = (JSONParser,)
     permission_classes = (NoPermission,)
 
     def build_cursor_link(self, request, name, cursor):

+ 0 - 16
src/sentry/api/content_negotiation.py

@@ -1,16 +0,0 @@
-from __future__ import absolute_import
-
-from rest_framework.negotiation import DefaultContentNegotiation
-from rest_framework.parsers import FormParser, MultiPartParser
-
-
-class ConditionalContentNegotiation(DefaultContentNegotiation):
-    """
-    Overrides the parsers on POST to support file uploads.
-    """
-
-    def select_parser(self, request, parsers):
-        if request.method == "POST":
-            parsers = [FormParser(), MultiPartParser()]
-
-        return super(ConditionalContentNegotiation, self).select_parser(request, parsers)

+ 0 - 3
src/sentry/api/endpoints/debug_files.py

@@ -14,7 +14,6 @@ from sentry import ratelimits
 
 from sentry.api.base import DocSection
 from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission
-from sentry.api.content_negotiation import ConditionalContentNegotiation
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.serializers import serialize
 from sentry.constants import KNOWN_DIF_FORMATS
@@ -53,8 +52,6 @@ class DebugFilesEndpoint(ProjectEndpoint):
     doc_section = DocSection.PROJECTS
     permission_classes = (ProjectReleasePermission,)
 
-    content_negotiation_class = ConditionalContentNegotiation
-
     def download(self, debug_file_id, project):
         rate_limited = ratelimits.is_limited(
             project=project,

+ 0 - 2
src/sentry/api/endpoints/organization_release_files.py

@@ -7,7 +7,6 @@ from rest_framework.response import Response
 
 from sentry.api.base import DocSection
 from sentry.api.bases.organization import OrganizationReleasesBaseEndpoint
-from sentry.api.content_negotiation import ConditionalContentNegotiation
 from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.serializers import serialize
@@ -40,7 +39,6 @@ def load_dist(results):
 
 class OrganizationReleaseFilesEndpoint(OrganizationReleasesBaseEndpoint):
     doc_section = DocSection.RELEASES
-    content_negotiation_class = ConditionalContentNegotiation
 
     def get(self, request, organization, version):
         """

+ 0 - 2
src/sentry/api/endpoints/project_release_files.py

@@ -8,7 +8,6 @@ from rest_framework.response import Response
 
 from sentry.api.base import DocSection
 from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission
-from sentry.api.content_negotiation import ConditionalContentNegotiation
 from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.serializers import serialize
@@ -53,7 +52,6 @@ def list_files_scenario(runner):
 
 class ProjectReleaseFilesEndpoint(ProjectEndpoint):
     doc_section = DocSection.RELEASES
-    content_negotiation_class = ConditionalContentNegotiation
     permission_classes = (ProjectReleasePermission,)
 
     @attach_scenarios([list_files_scenario])

+ 6 - 0
src/sentry/conf/server.py

@@ -776,6 +776,12 @@ LOGGING = {
 # django-rest-framework
 
 REST_FRAMEWORK = {
+    "DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer"],
+    "DEFAULT_PARSER_CLASSES": [
+        "rest_framework.parsers.JSONParser",
+        "rest_framework.parsers.MultiPartParser",
+        "rest_framework.parsers.FormParser",
+    ],
     "TEST_REQUEST_DEFAULT_FORMAT": "json",
     "DEFAULT_PERMISSION_CLASSES": ("sentry.api.permissions.NoPermission",),
     "EXCEPTION_HANDLER": "sentry.api.handlers.custom_exception_handler",

+ 10 - 11
tests/sentry/api/endpoints/test_chunk_upload.py

@@ -63,21 +63,20 @@ class ChunkUploadTest(APITestCase):
         assert response.status_code == 403, response.content
 
     def test_upload(self):
-        string1 = "1 this is my testString"
-        string2 = "2 this is my testString"
-
-        checksum1 = sha1(string1).hexdigest()
-        checksum2 = sha1(string2).hexdigest()
+        data1 = "1 this is my testString"
+        data2 = "2 this is my testString"
+        checksum1 = sha1(data1).hexdigest()
+        checksum2 = sha1(data2).hexdigest()
+        blob1 = SimpleUploadedFile(checksum1, data1, content_type="multipart/form-data")
+        blob2 = SimpleUploadedFile(checksum2, data2, content_type="multipart/form-data")
 
         response = self.client.post(
             self.url,
-            data={
-                "file": [
-                    SimpleUploadedFile(checksum1, string1),
-                    SimpleUploadedFile(checksum2, string2),
-                ]
-            },
+            data={"file": [blob1, blob2]},
             HTTP_AUTHORIZATION=u"Bearer {}".format(self.token.token),
+            # this tells drf to select the MultiPartParser. We use that instead of
+            # FileUploadParser because we have our own specific file chunking mechanism
+            # in the chunk endpoint that has requirements like blob/chunk's filename = checksum.
             format="multipart",
         )