diff options
| author | Krzysztof Jurewicz | 2013-11-19 15:49:31 +0100 |
|---|---|---|
| committer | Krzysztof Jurewicz | 2013-11-19 15:49:31 +0100 |
| commit | 9cea6880f7103c4e9407f975753c830f109c8c7c (patch) | |
| tree | 1a45f020f5fa471842eff57131ae3ab3ef9b0fd0 /rest_framework/mixins.py | |
| parent | ca2bd616d989f78d00641231e645198a6c95caa0 (diff) | |
| download | django-rest-framework-9cea6880f7103c4e9407f975753c830f109c8c7c.tar.bz2 | |
Added handling of validation errors in PUT-as-create.
Fixes #1035.
Diffstat (limited to 'rest_framework/mixins.py')
| -rw-r--r-- | rest_framework/mixins.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 4606c78b..79f79c30 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -6,6 +6,7 @@ which allows mixin classes to be composed in interesting ways. """ from __future__ import unicode_literals +from django.core.exceptions import ValidationError from django.http import Http404 from rest_framework import status from rest_framework.response import Response @@ -127,7 +128,12 @@ class UpdateModelMixin(object): files=request.FILES, partial=partial) if serializer.is_valid(): - self.pre_save(serializer.object) + try: + self.pre_save(serializer.object) + except ValidationError as err: + # full_clean on model instance may be called in pre_save, so we + # have to handle eventual errors. + return Response(err.message_dict, status=status.HTTP_400_BAD_REQUEST) self.object = serializer.save(**save_kwargs) self.post_save(self.object, created=created) return Response(serializer.data, status=success_status_code) |
