aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2024-03-30 12:13:34 -0700
committerGravatar GitHub <[email protected]>2024-03-30 12:13:34 -0700
commit3f5a5e988cfc707bb8533106384280ab4172cf90 (patch)
tree43a2f9ffb21d3e93433ba39b9dfead942b4212c9 /pydis_site/apps/api/viewsets
parentSupport running tests with --keepdb option (diff)
parentMerge pull request #1271 from python-discord/dependabot/pip/djangorestframewo... (diff)
Merge branch 'main' into support-test-keepdb
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