| 215 | return self.instance |
| 216 | |
| 217 | def is_valid(self, *, raise_exception=False): |
| 218 | assert hasattr(self, 'initial_data'), ( |
| 219 | 'Cannot call `.is_valid()` as no `data=` keyword argument was ' |
| 220 | 'passed when instantiating the serializer instance.' |
| 221 | ) |
| 222 | |
| 223 | if not hasattr(self, '_validated_data'): |
| 224 | try: |
| 225 | self._validated_data = self.run_validation(self.initial_data) |
| 226 | except ValidationError as exc: |
| 227 | self._validated_data = {} |
| 228 | self._errors = exc.detail |
| 229 | else: |
| 230 | self._errors = {} |
| 231 | |
| 232 | if self._errors and raise_exception: |
| 233 | raise ValidationError(self.errors) |
| 234 | |
| 235 | return not bool(self._errors) |
| 236 | |
| 237 | @property |
| 238 | def data(self): |