From 9f5f314e2f01b2a08546d6904d27674d9a7db213 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 29 Mar 2024 13:10:42 +0100 Subject: Implement adjustments for DRF 3.15 --- pydis_site/apps/api/viewsets/bot/infraction.py | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'pydis_site/apps/api/viewsets') 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 -- cgit v1.2.3