Skip to content

Commit

Permalink
Reraise validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Oct 21, 2024
1 parent 0fbfa2f commit c32bdbd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions arches_lingo/views/api/pythonic_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from functools import partial

from django.core.exceptions import ValidationError as DjangoValidationError
from rest_framework.exceptions import ValidationError
from rest_framework.permissions import IsAuthenticated
from rest_framework.generics import RetrieveUpdateDestroyAPIView

Expand All @@ -26,6 +28,27 @@ def update(self, request, *args, **kwargs):
self.get_object = partial(self.get_object, user=request.user)
return super().update(request, *args, **kwargs)

def perform_update(self, serializer):
"""Re-raise ValidationError as DRF ValidationError.
In 3.0 (2014), DRF decided to stop full_clean()'ing before save(),
which divorces DRF validation needs from model logic needing to
support the Django admin or similar ModelFormish patterns.
The stated reasons were:
- to avoid needing to know about big & scary full_clean(). Fine.
- to force expressing validation logic outside of models.
but to adhere to *that* here would require some way of generically
validating incoming tile data without knowledge of the resource/graph,
which isn't practical under this implementation.
Discussion:
https://github.com/encode/django-rest-framework/discussions/7850
"""
try:
serializer.save()
except DjangoValidationError as django_error:
raise ValidationError(detail=django_error) from django_error


class SchemeDetailView(PythonicModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [IsAuthenticated]
Expand Down

0 comments on commit c32bdbd

Please sign in to comment.