Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from skbkontur/does-not-exists
Browse files Browse the repository at this point in the history
correct not found validation
  • Loading branch information
andruha authored Oct 23, 2019
2 parents b22813a + 416704d commit f921c31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions rest_framework_bulk/drf3/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import print_function, unicode_literals

import inspect

from rest_framework.exceptions import ValidationError
from rest_framework.fields import SkipField
from rest_framework.serializers import ListSerializer
from rest_framework.settings import api_settings
from rest_framework.utils import html
from rest_framework.fields import SkipField


__all__ = [
'BulkListSerializer',
Expand Down Expand Up @@ -115,8 +115,13 @@ def to_internal_value(self, data):

for item in data:
try:
self.child.instance = self.instance.get(id=item['id']) if self.instance else None
self.child.initial_data = item
if self.instance:
try:
self.child.instance = self.instance.get(id=item['id'])
self.child.initial_data = item
except getattr(self.child.Meta.model, 'DoesNotExist') as exc:
raise ValidationError({'non_field_errors': [str(exc)]})

validated = self.child.run_validation(item)
except ValidationError as exc:
errors.append(exc.detail)
Expand Down
1 change: 0 additions & 1 deletion rest_framework_bulk/tests/simple_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
router.register('simple', SimpleViewSet, 'simple')

urlpatterns = (
'',
url(r'^api/', include(router.urls)),
)

0 comments on commit f921c31

Please sign in to comment.