MCPcopy
hub / github.com/encode/django-rest-framework / is_valid

Method is_valid

rest_framework/serializers.py:779–799  ·  view source on GitHub ↗
(self, *, raise_exception=False)

Source from the content-addressed store, hash-verified

777 return self.instance
778
779 def is_valid(self, *, raise_exception=False):
780 # This implementation is the same as the default,
781 # except that we use lists, rather than dicts, as the empty case.
782 assert hasattr(self, 'initial_data'), (
783 'Cannot call `.is_valid()` as no `data=` keyword argument was '
784 'passed when instantiating the serializer instance.'
785 )
786
787 if not hasattr(self, '_validated_data'):
788 try:
789 self._validated_data = self.run_validation(self.initial_data)
790 except ValidationError as exc:
791 self._validated_data = []
792 self._errors = exc.detail
793 else:
794 self._errors = []
795
796 if self._errors and raise_exception:
797 raise ValidationError(self.errors)
798
799 return not bool(self._errors)
800
801 def __repr__(self):
802 return representation.list_repr(self, indent=1)

Calls 2

run_validationMethod · 0.95
ValidationErrorClass · 0.90