aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2024-03-29 13:10:42 +0100
committerGravatar Johannes Christ <[email protected]>2024-03-29 13:27:28 +0100
commit9f5f314e2f01b2a08546d6904d27674d9a7db213 (patch)
treea2ed752d93c3210a2282eab9687323690e9b8558 /pydis_site/apps/api/viewsets
parentBump djangorestframework from 3.14.0 to 3.15.1 (diff)
Implement adjustments for DRF 3.15
Diffstat (limited to 'pydis_site/apps/api/viewsets')
-rw-r--r--pydis_site/apps/api/viewsets/bot/infraction.py26
1 files changed, 0 insertions, 26 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py
index 8da82822..254a588d 100644
--- a/pydis_site/apps/api/viewsets/bot/infraction.py
+++ b/pydis_site/apps/api/viewsets/bot/infraction.py
@@ -1,6 +1,5 @@
import datetime
-from django.db import IntegrityError
from django.db.models import QuerySet
from django.http.request import HttpRequest
from django_filters.rest_framework import DjangoFilterBackend
@@ -275,28 +274,3 @@ class InfractionViewSet(
"""
self.serializer_class = ExpandedInfractionSerializer
return self.partial_update(*args, **kwargs)
-
- def create(self, request: HttpRequest, *args, **kwargs) -> Response:
- """
- Create an infraction for a target user.
-
- Called by the Django Rest Framework in response to the corresponding HTTP request.
- """
- try:
- return super().create(request, *args, **kwargs)
- except IntegrityError as err:
- # We need to use `__cause__` here, as Django reraises the internal
- # UniqueViolation emitted by psycopg2 (which contains the attribute
- # that we actually need)
- #
- # _meta is documented and mainly named that way to prevent
- # name clashes: https://docs.djangoproject.com/en/dev/ref/models/meta/
- if err.__cause__.diag.constraint_name == Infraction._meta.constraints[0].name:
- raise ValidationError(
- {
- 'non_field_errors': [
- 'This user already has an active infraction of this type.',
- ]
- }
- )
- raise # pragma: no cover - no other constraint to test with