diff options
| author | Tom Christie | 2015-02-26 15:56:18 +0000 | 
|---|---|---|
| committer | Tom Christie | 2015-02-26 15:56:18 +0000 | 
| commit | c66f23391ac669f2a9a27431e66588e9092300f2 (patch) | |
| tree | 46aa41a51ba19deb0b99eaca72b443ca12d9a0e1 /rest_framework | |
| parent | d219fc0d8179532c17745dd4aaabd38a2f3faa82 (diff) | |
| parent | aa7ed316d842c06d7eb6907d4481d72c747991d7 (diff) | |
| download | django-rest-framework-c66f23391ac669f2a9a27431e66588e9092300f2.tar.bz2 | |
Merge pull request #2572 from Ins1ne/master
Fix UniqueTogetherValidator for NULL values
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/validators.py | 7 | 
1 files changed, 6 insertions, 1 deletions
| diff --git a/rest_framework/validators.py b/rest_framework/validators.py index e3719b8d..ab361614 100644 --- a/rest_framework/validators.py +++ b/rest_framework/validators.py @@ -138,7 +138,12 @@ class UniqueTogetherValidator:          queryset = self.queryset          queryset = self.filter_queryset(attrs, queryset)          queryset = self.exclude_current_instance(attrs, queryset) -        if queryset.exists(): + +        # Ignore validation if any field is None +        checked_values = [ +            value for field, value in attrs.items() if field in self.fields +        ] +        if None not in checked_values and queryset.exists():              field_names = ', '.join(self.fields)              raise ValidationError(self.message.format(field_names=field_names)) | 
