-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly raise an error when updating release component with unknow…
…n fields. Params like `release` and `global_component` will not pass cliently now.
- Loading branch information
Showing
2 changed files
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from django.shortcuts import get_object_or_404 | ||
from django.utils import six | ||
from django.utils.text import capfirst | ||
from django.core.exceptions import FieldError | ||
|
||
from rest_framework import serializers | ||
from rest_framework.validators import UniqueTogetherValidator | ||
|
@@ -370,8 +371,12 @@ def to_representation(self, instance): | |
return ret | ||
|
||
def to_internal_value(self, data): | ||
# For Update request, restore release and global_component for unique validation. | ||
# Raise error explictly when release and global_component is given. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if self.instance: | ||
allowed_keys = self.get_allowed_keys() - set(['release', 'global_component']) | ||
extra_fields = set(data.keys()) - allowed_keys | ||
if extra_fields: | ||
This comment has been minimized.
Sorry, something went wrong.
lubomir
Member
|
||
raise FieldError('Unknown fields: %s.' % ', '.join('"%s"' % f for f in extra_fields)) | ||
data['release'] = self.instance.release | ||
data['global_component'] = self.instance.global_component | ||
return super(ReleaseComponentSerializer, self).to_internal_value(data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ignore this comment. I did not see the detail