We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IntegrityError in ratings
See:
- https://sentry.liqd.net/sentry/debattenportalspdde/issues/84/
- https://sentry.liqd.net/sentry/meinberlin-prod/issues/5/

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `adhocracy4/ratings/api.py`
Content:
```
1 from django.conf import settings
2 
3 from django_filters import rest_framework as filters
4 from rest_framework import mixins, viewsets
5 from rest_framework.response import Response
6 
7 from adhocracy4.api.mixins import ContentTypeMixin
8 from adhocracy4.api.permissions import ViewSetRulesPermission
9 
10 from .models import Rating
11 from .serializers import RatingSerializer
12 
13 
14 class RatingViewSet(mixins.CreateModelMixin,
15                     mixins.UpdateModelMixin,
16                     ContentTypeMixin,
17                     viewsets.GenericViewSet):
18 
19     queryset = Rating.objects.all()
20     serializer_class = RatingSerializer
21     permission_classes = (ViewSetRulesPermission,)
22     filter_backends = (filters.DjangoFilterBackend,)
23     filter_fields = ('object_pk', 'content_type')
24     content_type_filter = settings.A4_RATEABLES
25 
26     def perform_create(self, serializer):
27         serializer.save(
28             content_object=self.content_object,
29             creator=self.request.user
30         )
31 
32     def get_permission_object(self):
33         return self.content_object
34 
35     @property
36     def rules_method_map(self):
37         return ViewSetRulesPermission.default_rules_method_map._replace(
38             POST='{app_label}.rate_{model}'.format(
39                 app_label=self.content_type.app_label,
40                 model=self.content_type.model
41             )
42         )
43 
44     def destroy(self, request, content_type, object_pk, pk=None):
45         """
46         Sets value to zero
47         NOTE: Rating is NOT deleted.
48         """
49         rating = self.get_object()
50         rating.update(0)
51         serializer = self.get_serializer(rating)
52         return Response(serializer.data)
53
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/adhocracy4/ratings/api.py b/adhocracy4/ratings/api.py
--- a/adhocracy4/ratings/api.py
+++ b/adhocracy4/ratings/api.py
@@ -3,6 +3,7 @@
 from django_filters import rest_framework as filters
 from rest_framework import mixins, viewsets
 from rest_framework.response import Response
+from rest_framework.serializers import ValidationError
 
 from adhocracy4.api.mixins import ContentTypeMixin
 from adhocracy4.api.permissions import ViewSetRulesPermission
@@ -24,6 +25,11 @@
     content_type_filter = settings.A4_RATEABLES
 
     def perform_create(self, serializer):
+        queryset = Rating.objects.filter(content_type_id=self.content_type.pk,
+                                         creator=self.request.user,
+                                         object_pk=self.content_object.pk)
+        if queryset.exists():
+            raise ValidationError(queryset[0].pk)
         serializer.save(
             content_object=self.content_object,
             creator=self.request.user

{"golden_diff": "diff --git a/adhocracy4/ratings/api.py b/adhocracy4/ratings/api.py\n--- a/adhocracy4/ratings/api.py\n+++ b/adhocracy4/ratings/api.py\n@@ -3,6 +3,7 @@\n from django_filters import rest_framework as filters\n from rest_framework import mixins, viewsets\n from rest_framework.response import Response\n+from rest_framework.serializers import ValidationError\n \n from adhocracy4.api.mixins import ContentTypeMixin\n from adhocracy4.api.permissions import ViewSetRulesPermission\n@@ -24,6 +25,11 @@\n     content_type_filter = settings.A4_RATEABLES\n \n     def perform_create(self, serializer):\n+        queryset = Rating.objects.filter(content_type_id=self.content_type.pk,\n+                                         creator=self.request.user,\n+                                         object_pk=self.content_object.pk)\n+        if queryset.exists():\n+            raise ValidationError(queryset[0].pk)\n         serializer.save(\n             content_object=self.content_object,\n             creator=self.request.user\n", "issue": "IntegrityError in ratings\nSee:\r\n- https://sentry.liqd.net/sentry/debattenportalspdde/issues/84/\r\n- https://sentry.liqd.net/sentry/meinberlin-prod/issues/5/\n", "before_files": [{"content": "from django.conf import settings\n\nfrom django_filters import rest_framework as filters\nfrom rest_framework import mixins, viewsets\nfrom rest_framework.response import Response\n\nfrom adhocracy4.api.mixins import ContentTypeMixin\nfrom adhocracy4.api.permissions import ViewSetRulesPermission\n\nfrom .models import Rating\nfrom .serializers import RatingSerializer\n\n\nclass RatingViewSet(mixins.CreateModelMixin,\n                    mixins.UpdateModelMixin,\n                    ContentTypeMixin,\n                    viewsets.GenericViewSet):\n\n    queryset = Rating.objects.all()\n    serializer_class = RatingSerializer\n    permission_classes = (ViewSetRulesPermission,)\n    filter_backends = (filters.DjangoFilterBackend,)\n    filter_fields = ('object_pk', 'content_type')\n    content_type_filter = settings.A4_RATEABLES\n\n    def perform_create(self, serializer):\n        serializer.save(\n            content_object=self.content_object,\n            creator=self.request.user\n        )\n\n    def get_permission_object(self):\n        return self.content_object\n\n    @property\n    def rules_method_map(self):\n        return ViewSetRulesPermission.default_rules_method_map._replace(\n            POST='{app_label}.rate_{model}'.format(\n                app_label=self.content_type.app_label,\n                model=self.content_type.model\n            )\n        )\n\n    def destroy(self, request, content_type, object_pk, pk=None):\n        \"\"\"\n        Sets value to zero\n        NOTE: Rating is NOT deleted.\n        \"\"\"\n        rating = self.get_object()\n        rating.update(0)\n        serializer = self.get_serializer(rating)\n        return Response(serializer.data)\n", "path": "adhocracy4/ratings/api.py"}], "after_files": [{"content": "from django.conf import settings\n\nfrom django_filters import rest_framework as filters\nfrom rest_framework import mixins, viewsets\nfrom rest_framework.response import Response\nfrom rest_framework.serializers import ValidationError\n\nfrom adhocracy4.api.mixins import ContentTypeMixin\nfrom adhocracy4.api.permissions import ViewSetRulesPermission\n\nfrom .models import Rating\nfrom .serializers import RatingSerializer\n\n\nclass RatingViewSet(mixins.CreateModelMixin,\n                    mixins.UpdateModelMixin,\n                    ContentTypeMixin,\n                    viewsets.GenericViewSet):\n\n    queryset = Rating.objects.all()\n    serializer_class = RatingSerializer\n    permission_classes = (ViewSetRulesPermission,)\n    filter_backends = (filters.DjangoFilterBackend,)\n    filter_fields = ('object_pk', 'content_type')\n    content_type_filter = settings.A4_RATEABLES\n\n    def perform_create(self, serializer):\n        queryset = Rating.objects.filter(content_type_id=self.content_type.pk,\n                                         creator=self.request.user,\n                                         object_pk=self.content_object.pk)\n        if queryset.exists():\n            raise ValidationError(queryset[0].pk)\n        serializer.save(\n            content_object=self.content_object,\n            creator=self.request.user\n        )\n\n    def get_permission_object(self):\n        return self.content_object\n\n    @property\n    def rules_method_map(self):\n        return ViewSetRulesPermission.default_rules_method_map._replace(\n            POST='{app_label}.rate_{model}'.format(\n                app_label=self.content_type.app_label,\n                model=self.content_type.model\n            )\n        )\n\n    def destroy(self, request, content_type, object_pk, pk=None):\n        \"\"\"\n        Sets value to zero\n        NOTE: Rating is NOT deleted.\n        \"\"\"\n        rating = self.get_object()\n        rating.update(0)\n        serializer = self.get_serializer(rating)\n        return Response(serializer.data)\n", "path": "adhocracy4/ratings/api.py"}]}