Browse Source

ref: (Django 1.9) Bump djangorestframework to 3.0.5 as an intermediate step to get to 3.3.x

Upgrade to next major version of django rest framework. This diff is fairly large, but this is the
minimum set of changes I could make to have the upgrade pass. Mostly things are drop in renames,
so there aren't really sweeping changes here.

Things done:

- serializer.object replaced with serializer.validated_data. For standard serializers this is a
  drop in replacement. For model serializers we get a dictionary rather than the instance, so need
  to translate usage accordingly.
- on serializer fields, replace allow_none with allow_null
- on field validation methods in serializers (ie validate_<fieldname>) change parameters to just
  value, rather than attrs, source. This means that values are just passed directly to the
  validation method rather than us having to look them up. In cases where we use attrs to look up
  other values we do so in validate
- replaced uses of init_data with initial_data on serializers
- add allow_blank and allow_null as necessary to replicate previous behaviour. These need to be
  specified explicitly now.
- Replace uses of Serializer.base_fields with Serializer().fields. These are equivalent
- Convert all WritableField classes to Field. Fields are now writeable by default.
- Replace our vendorized ListField with the DRF version
- For custom fields, rename from_native to to_internal_value, and to_native to to_representation.
  These are drop in replacement get_default_fields has been removed. get_fields works as a
  replacement, but doesn't operate in quite the same way, so restructed the validators for monitors.
Dan Fuller 5 years ago
parent
commit
65b8c65d28

+ 1 - 0
.travis.yml

@@ -120,6 +120,7 @@ matrix:
       name: 'Linter'
       env: TEST_SUITE=lint
       install:
+        - python setup.py install_egg_info
         - SENTRY_LIGHT_BUILD=1 pip install -U -e ".[dev,tests,optional]"
         - find "$NODE_DIR" -type d -empty -delete
         - nvm install

+ 1 - 1
requirements-base.txt

@@ -12,7 +12,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>=2.4.8,<2.5.0
+djangorestframework==3.0.5
 email-reply-parser>=0.2.0,<0.3.0
 enum34>=1.1.6,<1.2.0
 exam>=0.5.1

+ 1 - 1
src/sentry/api/bases/avatar.py

@@ -59,7 +59,7 @@ class AvatarMixin(object):
         if not serializer.is_valid():
             return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 
-        result = serializer.object
+        result = serializer.validated_data
 
         self.model.save_avatar(
             relation={self.object_type: obj},

+ 8 - 11
src/sentry/api/bases/discoversavedquery.py

@@ -10,20 +10,19 @@ class DiscoverSavedQuerySerializer(serializers.Serializer):
     projects = ListField(
         child=serializers.IntegerField(),
         required=False,
-        allow_null=True,
         default=[]
     )
-    start = serializers.DateTimeField(required=False)
-    end = serializers.DateTimeField(required=False)
-    range = serializers.CharField(required=False, allow_none=True)
+    start = serializers.DateTimeField(required=False, allow_null=True)
+    end = serializers.DateTimeField(required=False, allow_null=True)
+    range = serializers.CharField(required=False, allow_null=True)
     fields = ListField(
         child=serializers.CharField(),
         required=False,
         allow_null=True,
     )
-    limit = serializers.IntegerField(min_value=0, max_value=1000, required=False)
-    rollup = serializers.IntegerField(required=False)
-    orderby = serializers.CharField(required=False)
+    limit = serializers.IntegerField(min_value=0, max_value=1000, required=False, allow_null=True)
+    rollup = serializers.IntegerField(required=False, allow_null=True)
+    orderby = serializers.CharField(required=False, allow_null=True)
     conditions = ListField(
         child=ListField(),
         required=False,
@@ -32,7 +31,6 @@ class DiscoverSavedQuerySerializer(serializers.Serializer):
     aggregations = ListField(
         child=ListField(),
         required=False,
-        allow_null=True,
         default=[]
     )
     groupby = ListField(
@@ -41,9 +39,8 @@ class DiscoverSavedQuerySerializer(serializers.Serializer):
         allow_null=True,
     )
 
-    def validate_projects(self, attrs, source):
+    def validate_projects(self, projects):
         organization = self.context['organization']
-        projects = attrs[source]
 
         org_projects = set(Project.objects.filter(
             organization=organization,
@@ -54,7 +51,7 @@ class DiscoverSavedQuerySerializer(serializers.Serializer):
         if set(projects) != org_projects:
             raise PermissionDenied
 
-        return attrs
+        return projects
 
     def validate(self, data):
         query = {}

+ 3 - 3
src/sentry/api/bases/project.py

@@ -152,9 +152,9 @@ class ProjectEndpoint(Endpoint):
     def handle_exception(self, request, exc):
         if isinstance(exc, ProjectMoved):
             response = Response({
-                'slug': exc.detail['extra']['slug'],
-                'detail': exc.detail
+                'slug': exc.detail['detail']['extra']['slug'],
+                'detail': exc.detail['detail']
             }, status=exc.status_code)
-            response['Location'] = exc.detail['extra']['url']
+            response['Location'] = exc.detail['detail']['extra']['url']
             return response
         return super(ProjectEndpoint, self).handle_exception(request, exc)

+ 7 - 1
src/sentry/api/endpoints/api_application_details.py

@@ -31,14 +31,20 @@ class ApiApplicationSerializer(serializers.Serializer):
     homepageUrl = serializers.URLField(
         max_length=255,
         required=False,
+        allow_null=True,
+        allow_blank=True,
     )
     termsUrl = serializers.URLField(
         max_length=255,
         required=False,
+        allow_null=True,
+        allow_blank=True,
     )
     privacyUrl = serializers.URLField(
         max_length=255,
         required=False,
+        allow_null=True,
+        allow_blank=True,
     )
 
 
@@ -71,7 +77,7 @@ class ApiApplicationDetailsEndpoint(Endpoint):
         serializer = ApiApplicationSerializer(data=request.DATA, partial=True)
 
         if serializer.is_valid():
-            result = serializer.object
+            result = serializer.validated_data
             kwargs = {}
             if 'name' in result:
                 kwargs['name'] = result['name']

+ 1 - 1
src/sentry/api/endpoints/api_tokens.py

@@ -37,7 +37,7 @@ class ApiTokensEndpoint(Endpoint):
         serializer = ApiTokenSerializer(data=request.DATA)
 
         if serializer.is_valid():
-            result = serializer.object
+            result = serializer.validated_data
 
             token = ApiToken.objects.create(
                 user=request.user,

+ 2 - 3
src/sentry/api/endpoints/assistant.py

@@ -24,15 +24,14 @@ class AssistantSerializer(serializers.Serializer):
     )
     useful = serializers.BooleanField()
 
-    def validate_guide_id(self, attrs, source):
-        value = attrs[source]
+    def validate_guide_id(self, value):
         valid_ids = manager.get_valid_ids()
 
         if not value:
             raise serializers.ValidationError('Assistant guide id is required')
         if value not in valid_ids:
             raise serializers.ValidationError('Not a valid assistant guide id')
-        return attrs
+        return value
 
 
 class AssistantEndpoint(Endpoint):

+ 4 - 4
src/sentry/api/endpoints/auth_index.py

@@ -106,14 +106,14 @@ class AuthIndexEndpoint(Endpoint):
         authenticated = False
 
         # See if we have a u2f challenge/response
-        if 'challenge' in validator.object and 'response' in validator.object:
+        if 'challenge' in validator.validated_data and 'response' in validator.validated_data:
             try:
                 interface = Authenticator.objects.get_interface(request.user, 'u2f')
                 if not interface.is_enrolled:
                     raise LookupError()
 
-                challenge = json.loads(validator.object['challenge'])
-                response = json.loads(validator.object['response'])
+                challenge = json.loads(validator.validated_data['challenge'])
+                response = json.loads(validator.validated_data['response'])
                 authenticated = interface.validate_response(request, challenge, response)
             except ValueError:
                 pass
@@ -122,7 +122,7 @@ class AuthIndexEndpoint(Endpoint):
 
         # attempt password authentication
         else:
-            authenticated = request.user.check_password(validator.object['password'])
+            authenticated = request.user.check_password(validator.validated_data['password'])
 
         # UI treats 401s by redirecting, this 401 should be ignored
         if not authenticated:

+ 1 - 1
src/sentry/api/endpoints/broadcast_details.py

@@ -58,7 +58,7 @@ class BroadcastDetailsEndpoint(Endpoint):
         if not validator.is_valid():
             return self.respond(validator.errors, status=400)
 
-        result = validator.object
+        result = validator.validated_data
 
         update_kwargs = {}
         if result.get('title'):

Some files were not shown because too many files changed in this diff