From cf7b9958146329b7350c99cc8216fc866f7c37c8 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Tue, 27 May 2025 08:27:04 +0200 Subject: Do not activate infractions on partial updates --- pydis_site/apps/api/viewsets/bot/infraction.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (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 066b296f..1d16232c 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -161,7 +161,12 @@ class InfractionViewSet( def partial_update(self, request: HttpRequest, *_args, **_kwargs) -> Response: """Method that handles the nuts and bolts of updating an Infraction.""" instance = self.get_object() - request.data.setdefault("active", True) + # DRF presently errors out if we are not specifying all fields here. + # See this issue: + # https://github.com/encode/django-rest-framework/issues/9358. The + # merged PR that closed the issue does not appear to work either, so + # here's a workaround. + request.data.setdefault("active", instance.active) serializer = self.get_serializer(instance, data=request.data, partial=True) serializer.is_valid(raise_exception=True) serializer.save() -- cgit v1.2.3