We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Event registrations api returns 500
### Describe the bug
`/api/v1/events/{pk}/registrations/` returns a 500

### How to reproduce
1. Register for an event
2. Go to `/api/v1/events/{pk}/registrations/`
3. See a 500

### Expected behaviour
No 500


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `website/events/api/v1/serializers/event_registrations/list.py`
Content:
```
1 from django.conf import settings
2 from django.templatetags.static import static
3 from rest_framework import serializers
4 from rest_framework.fields import empty
5 
6 from events import services
7 from events.exceptions import RegistrationError
8 from events.models import EventRegistration, RegistrationInformationField
9 from payments.api.v1.fields import PaymentTypeField
10 from payments.models import Payment
11 from thaliawebsite.api.services import create_image_thumbnail_dict
12 
13 
14 class EventRegistrationListSerializer(serializers.ModelSerializer):
15     """Custom registration list serializer."""
16 
17     class Meta:
18         model = EventRegistration
19         fields = ("pk", "member", "name", "avatar")
20 
21     name = serializers.SerializerMethodField("_name")
22     avatar = serializers.SerializerMethodField("_avatar")
23     member = serializers.SerializerMethodField("_member")
24 
25     def _member(self, instance):
26         if instance.member:
27             return instance.member.pk
28         return None
29 
30     def _name(self, instance):
31         if instance.member:
32             return instance.member.profile.display_name()
33         return instance.name
34 
35     def _avatar(self, instance):
36         placeholder = self.context["request"].build_absolute_uri(
37             static("members/images/default-avatar.jpg")
38         )
39         file = None
40         if instance.member and instance.member.profile.photo:
41             file = instance.member.profile.photo
42         return create_image_thumbnail_dict(
43             self.context["request"], file, placeholder=placeholder, size_large="800x800"
44         )
45 
46 
47 class EventRegistrationAdminListSerializer(EventRegistrationListSerializer):
48     """Custom registration admin list serializer."""
49 
50     class Meta:
51         model = EventRegistration
52         fields = (
53             "pk",
54             "member",
55             "name",
56             "registered_on",
57             "is_cancelled",
58             "is_late_cancellation",
59             "queue_position",
60             "payment",
61             "present",
62             "avatar",
63         )
64 
65     registered_on = serializers.DateTimeField(source="date")
66     is_cancelled = serializers.SerializerMethodField("_is_cancelled")
67     is_late_cancellation = serializers.SerializerMethodField("_is_late_cancellation")
68     queue_position = serializers.SerializerMethodField("_queue_position")
69     payment = PaymentTypeField(source="payment.type", choices=Payment.PAYMENT_TYPE)
70 
71     def _is_late_cancellation(self, instance):
72         return instance.is_late_cancellation()
73 
74     def _queue_position(self, instance):
75         pos = instance.queue_position
76         return pos if pos > 0 else None
77 
78     def _is_cancelled(self, instance):
79         return instance.date_cancelled is not None
80 
81     def _name(self, instance):
82         if instance.member:
83             return instance.member.get_full_name()
84         return instance.name
85 
86 
87 class EventRegistrationSerializer(serializers.ModelSerializer):
88     """Registration serializer."""
89 
90     information_fields = None
91 
92     class Meta:
93         model = EventRegistration
94         fields = (
95             "pk",
96             "member",
97             "name",
98             "photo",
99             "avatar",
100             "registered_on",
101             "is_late_cancellation",
102             "is_cancelled",
103             "queue_position",
104             "fields",
105             "payment",
106             "present",
107         )
108 
109     name = serializers.SerializerMethodField("_name")
110     photo = serializers.SerializerMethodField("_photo")
111     avatar = serializers.SerializerMethodField("_avatar")
112     member = serializers.SerializerMethodField("_member")
113     payment = PaymentTypeField(source="payment.type", choices=Payment.PAYMENT_TYPE)
114     registered_on = serializers.DateTimeField(source="date", read_only=True)
115     is_cancelled = serializers.SerializerMethodField("_is_cancelled")
116     is_late_cancellation = serializers.SerializerMethodField("_is_late_cancellation")
117     fields = serializers.HiddenField(default="")
118 
119     def _is_late_cancellation(self, instance):
120         val = instance.is_late_cancellation()
121         return False if val is None else val
122 
123     def _is_cancelled(self, instance):
124         return instance.date_cancelled is not None
125 
126     def _member(self, instance):
127         if instance.member:
128             return instance.member.pk
129         return None
130 
131     def _name(self, instance):
132         if instance.member:
133             return instance.member.profile.display_name()
134         return instance.name
135 
136     def _photo(self, instance):
137         if instance.member and instance.member.profile.photo:
138             return self.context["request"].build_absolute_uri(
139                 f"{settings.MEDIA_URL}{instance.member.profile.photo}"
140             )
141         return self.context["request"].build_absolute_uri(
142             static("members/images/default-avatar.jpg")
143         )
144 
145     def _avatar(self, instance):
146         placeholder = self.context["request"].build_absolute_uri(
147             static("members/images/default-avatar.jpg")
148         )
149         file = None
150         if instance.member and instance.member.profile.photo:
151             file = instance.member.profile.photo
152         return create_image_thumbnail_dict(
153             self.context["request"], file, placeholder=placeholder, size_large="800x800"
154         )
155 
156     def __init__(self, instance=None, data=empty, **kwargs):
157         super().__init__(instance, data, **kwargs)
158         try:
159             if instance:
160                 self.information_fields = services.registration_fields(
161                     kwargs["context"]["request"], registration=instance
162                 )
163         except RegistrationError:
164             pass
165 
166     def get_fields(self):
167         fields = super().get_fields()
168 
169         if self.information_fields:
170             for key, field in self.information_fields.items():
171                 key = "fields[{}]".format(key)
172                 field_type = field["type"]
173 
174                 if field_type == RegistrationInformationField.BOOLEAN_FIELD:
175                     fields[key] = serializers.BooleanField(
176                         required=False, write_only=True
177                     )
178                 elif field_type == RegistrationInformationField.INTEGER_FIELD:
179                     fields[key] = serializers.IntegerField(
180                         required=field["required"],
181                         write_only=True,
182                         allow_null=not field["required"],
183                     )
184                 elif field_type == RegistrationInformationField.TEXT_FIELD:
185                     fields[key] = serializers.CharField(
186                         required=field["required"],
187                         write_only=True,
188                         allow_blank=not field["required"],
189                         allow_null=not field["required"],
190                     )
191 
192                 fields[key].label = field["label"]
193                 fields[key].help_text = field["description"]
194                 fields[key].initial = field["value"]
195                 fields[key].default = field["value"]
196 
197                 try:
198                     if key in self.information_fields:
199                         fields[key].initial = self.validated_data[key]
200                 except AssertionError:
201                     pass
202 
203         return fields
204 
205     def to_representation(self, instance):
206         data = super().to_representation(instance)
207         data["fields"] = self.information_fields
208         return data
209 
210     def field_values(self):
211         return (
212             (name[7 : len(name) - 1], value)
213             for name, value in self.validated_data.items()
214             if "info_field" in name
215         )
216
```
--- 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/website/events/api/v1/serializers/event_registrations/list.py b/website/events/api/v1/serializers/event_registrations/list.py
--- a/website/events/api/v1/serializers/event_registrations/list.py
+++ b/website/events/api/v1/serializers/event_registrations/list.py
@@ -73,7 +73,7 @@
 
     def _queue_position(self, instance):
         pos = instance.queue_position
-        return pos if pos > 0 else None
+        return pos if pos and pos > 0 else None
 
     def _is_cancelled(self, instance):
         return instance.date_cancelled is not None

{"golden_diff": "diff --git a/website/events/api/v1/serializers/event_registrations/list.py b/website/events/api/v1/serializers/event_registrations/list.py\n--- a/website/events/api/v1/serializers/event_registrations/list.py\n+++ b/website/events/api/v1/serializers/event_registrations/list.py\n@@ -73,7 +73,7 @@\n \n     def _queue_position(self, instance):\n         pos = instance.queue_position\n-        return pos if pos > 0 else None\n+        return pos if pos and pos > 0 else None\n \n     def _is_cancelled(self, instance):\n         return instance.date_cancelled is not None\n", "issue": "Event registrations api returns 500\n### Describe the bug\r\n`/api/v1/events/{pk}/registrations/` returns a 500\r\n\r\n### How to reproduce\r\n1. Register for an event\r\n2. Go to `/api/v1/events/{pk}/registrations/`\r\n3. See a 500\r\n\r\n### Expected behaviour\r\nNo 500\r\n\n", "before_files": [{"content": "from django.conf import settings\nfrom django.templatetags.static import static\nfrom rest_framework import serializers\nfrom rest_framework.fields import empty\n\nfrom events import services\nfrom events.exceptions import RegistrationError\nfrom events.models import EventRegistration, RegistrationInformationField\nfrom payments.api.v1.fields import PaymentTypeField\nfrom payments.models import Payment\nfrom thaliawebsite.api.services import create_image_thumbnail_dict\n\n\nclass EventRegistrationListSerializer(serializers.ModelSerializer):\n    \"\"\"Custom registration list serializer.\"\"\"\n\n    class Meta:\n        model = EventRegistration\n        fields = (\"pk\", \"member\", \"name\", \"avatar\")\n\n    name = serializers.SerializerMethodField(\"_name\")\n    avatar = serializers.SerializerMethodField(\"_avatar\")\n    member = serializers.SerializerMethodField(\"_member\")\n\n    def _member(self, instance):\n        if instance.member:\n            return instance.member.pk\n        return None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.profile.display_name()\n        return instance.name\n\n    def _avatar(self, instance):\n        placeholder = self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n        file = None\n        if instance.member and instance.member.profile.photo:\n            file = instance.member.profile.photo\n        return create_image_thumbnail_dict(\n            self.context[\"request\"], file, placeholder=placeholder, size_large=\"800x800\"\n        )\n\n\nclass EventRegistrationAdminListSerializer(EventRegistrationListSerializer):\n    \"\"\"Custom registration admin list serializer.\"\"\"\n\n    class Meta:\n        model = EventRegistration\n        fields = (\n            \"pk\",\n            \"member\",\n            \"name\",\n            \"registered_on\",\n            \"is_cancelled\",\n            \"is_late_cancellation\",\n            \"queue_position\",\n            \"payment\",\n            \"present\",\n            \"avatar\",\n        )\n\n    registered_on = serializers.DateTimeField(source=\"date\")\n    is_cancelled = serializers.SerializerMethodField(\"_is_cancelled\")\n    is_late_cancellation = serializers.SerializerMethodField(\"_is_late_cancellation\")\n    queue_position = serializers.SerializerMethodField(\"_queue_position\")\n    payment = PaymentTypeField(source=\"payment.type\", choices=Payment.PAYMENT_TYPE)\n\n    def _is_late_cancellation(self, instance):\n        return instance.is_late_cancellation()\n\n    def _queue_position(self, instance):\n        pos = instance.queue_position\n        return pos if pos > 0 else None\n\n    def _is_cancelled(self, instance):\n        return instance.date_cancelled is not None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.get_full_name()\n        return instance.name\n\n\nclass EventRegistrationSerializer(serializers.ModelSerializer):\n    \"\"\"Registration serializer.\"\"\"\n\n    information_fields = None\n\n    class Meta:\n        model = EventRegistration\n        fields = (\n            \"pk\",\n            \"member\",\n            \"name\",\n            \"photo\",\n            \"avatar\",\n            \"registered_on\",\n            \"is_late_cancellation\",\n            \"is_cancelled\",\n            \"queue_position\",\n            \"fields\",\n            \"payment\",\n            \"present\",\n        )\n\n    name = serializers.SerializerMethodField(\"_name\")\n    photo = serializers.SerializerMethodField(\"_photo\")\n    avatar = serializers.SerializerMethodField(\"_avatar\")\n    member = serializers.SerializerMethodField(\"_member\")\n    payment = PaymentTypeField(source=\"payment.type\", choices=Payment.PAYMENT_TYPE)\n    registered_on = serializers.DateTimeField(source=\"date\", read_only=True)\n    is_cancelled = serializers.SerializerMethodField(\"_is_cancelled\")\n    is_late_cancellation = serializers.SerializerMethodField(\"_is_late_cancellation\")\n    fields = serializers.HiddenField(default=\"\")\n\n    def _is_late_cancellation(self, instance):\n        val = instance.is_late_cancellation()\n        return False if val is None else val\n\n    def _is_cancelled(self, instance):\n        return instance.date_cancelled is not None\n\n    def _member(self, instance):\n        if instance.member:\n            return instance.member.pk\n        return None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.profile.display_name()\n        return instance.name\n\n    def _photo(self, instance):\n        if instance.member and instance.member.profile.photo:\n            return self.context[\"request\"].build_absolute_uri(\n                f\"{settings.MEDIA_URL}{instance.member.profile.photo}\"\n            )\n        return self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n\n    def _avatar(self, instance):\n        placeholder = self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n        file = None\n        if instance.member and instance.member.profile.photo:\n            file = instance.member.profile.photo\n        return create_image_thumbnail_dict(\n            self.context[\"request\"], file, placeholder=placeholder, size_large=\"800x800\"\n        )\n\n    def __init__(self, instance=None, data=empty, **kwargs):\n        super().__init__(instance, data, **kwargs)\n        try:\n            if instance:\n                self.information_fields = services.registration_fields(\n                    kwargs[\"context\"][\"request\"], registration=instance\n                )\n        except RegistrationError:\n            pass\n\n    def get_fields(self):\n        fields = super().get_fields()\n\n        if self.information_fields:\n            for key, field in self.information_fields.items():\n                key = \"fields[{}]\".format(key)\n                field_type = field[\"type\"]\n\n                if field_type == RegistrationInformationField.BOOLEAN_FIELD:\n                    fields[key] = serializers.BooleanField(\n                        required=False, write_only=True\n                    )\n                elif field_type == RegistrationInformationField.INTEGER_FIELD:\n                    fields[key] = serializers.IntegerField(\n                        required=field[\"required\"],\n                        write_only=True,\n                        allow_null=not field[\"required\"],\n                    )\n                elif field_type == RegistrationInformationField.TEXT_FIELD:\n                    fields[key] = serializers.CharField(\n                        required=field[\"required\"],\n                        write_only=True,\n                        allow_blank=not field[\"required\"],\n                        allow_null=not field[\"required\"],\n                    )\n\n                fields[key].label = field[\"label\"]\n                fields[key].help_text = field[\"description\"]\n                fields[key].initial = field[\"value\"]\n                fields[key].default = field[\"value\"]\n\n                try:\n                    if key in self.information_fields:\n                        fields[key].initial = self.validated_data[key]\n                except AssertionError:\n                    pass\n\n        return fields\n\n    def to_representation(self, instance):\n        data = super().to_representation(instance)\n        data[\"fields\"] = self.information_fields\n        return data\n\n    def field_values(self):\n        return (\n            (name[7 : len(name) - 1], value)\n            for name, value in self.validated_data.items()\n            if \"info_field\" in name\n        )\n", "path": "website/events/api/v1/serializers/event_registrations/list.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.templatetags.static import static\nfrom rest_framework import serializers\nfrom rest_framework.fields import empty\n\nfrom events import services\nfrom events.exceptions import RegistrationError\nfrom events.models import EventRegistration, RegistrationInformationField\nfrom payments.api.v1.fields import PaymentTypeField\nfrom payments.models import Payment\nfrom thaliawebsite.api.services import create_image_thumbnail_dict\n\n\nclass EventRegistrationListSerializer(serializers.ModelSerializer):\n    \"\"\"Custom registration list serializer.\"\"\"\n\n    class Meta:\n        model = EventRegistration\n        fields = (\"pk\", \"member\", \"name\", \"avatar\")\n\n    name = serializers.SerializerMethodField(\"_name\")\n    avatar = serializers.SerializerMethodField(\"_avatar\")\n    member = serializers.SerializerMethodField(\"_member\")\n\n    def _member(self, instance):\n        if instance.member:\n            return instance.member.pk\n        return None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.profile.display_name()\n        return instance.name\n\n    def _avatar(self, instance):\n        placeholder = self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n        file = None\n        if instance.member and instance.member.profile.photo:\n            file = instance.member.profile.photo\n        return create_image_thumbnail_dict(\n            self.context[\"request\"], file, placeholder=placeholder, size_large=\"800x800\"\n        )\n\n\nclass EventRegistrationAdminListSerializer(EventRegistrationListSerializer):\n    \"\"\"Custom registration admin list serializer.\"\"\"\n\n    class Meta:\n        model = EventRegistration\n        fields = (\n            \"pk\",\n            \"member\",\n            \"name\",\n            \"registered_on\",\n            \"is_cancelled\",\n            \"is_late_cancellation\",\n            \"queue_position\",\n            \"payment\",\n            \"present\",\n            \"avatar\",\n        )\n\n    registered_on = serializers.DateTimeField(source=\"date\")\n    is_cancelled = serializers.SerializerMethodField(\"_is_cancelled\")\n    is_late_cancellation = serializers.SerializerMethodField(\"_is_late_cancellation\")\n    queue_position = serializers.SerializerMethodField(\"_queue_position\")\n    payment = PaymentTypeField(source=\"payment.type\", choices=Payment.PAYMENT_TYPE)\n\n    def _is_late_cancellation(self, instance):\n        return instance.is_late_cancellation()\n\n    def _queue_position(self, instance):\n        pos = instance.queue_position\n        return pos if pos and pos > 0 else None\n\n    def _is_cancelled(self, instance):\n        return instance.date_cancelled is not None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.get_full_name()\n        return instance.name\n\n\nclass EventRegistrationSerializer(serializers.ModelSerializer):\n    \"\"\"Registration serializer.\"\"\"\n\n    information_fields = None\n\n    class Meta:\n        model = EventRegistration\n        fields = (\n            \"pk\",\n            \"member\",\n            \"name\",\n            \"photo\",\n            \"avatar\",\n            \"registered_on\",\n            \"is_late_cancellation\",\n            \"is_cancelled\",\n            \"queue_position\",\n            \"fields\",\n            \"payment\",\n            \"present\",\n        )\n\n    name = serializers.SerializerMethodField(\"_name\")\n    photo = serializers.SerializerMethodField(\"_photo\")\n    avatar = serializers.SerializerMethodField(\"_avatar\")\n    member = serializers.SerializerMethodField(\"_member\")\n    payment = PaymentTypeField(source=\"payment.type\", choices=Payment.PAYMENT_TYPE)\n    registered_on = serializers.DateTimeField(source=\"date\", read_only=True)\n    is_cancelled = serializers.SerializerMethodField(\"_is_cancelled\")\n    is_late_cancellation = serializers.SerializerMethodField(\"_is_late_cancellation\")\n    fields = serializers.HiddenField(default=\"\")\n\n    def _is_late_cancellation(self, instance):\n        val = instance.is_late_cancellation()\n        return False if val is None else val\n\n    def _is_cancelled(self, instance):\n        return instance.date_cancelled is not None\n\n    def _member(self, instance):\n        if instance.member:\n            return instance.member.pk\n        return None\n\n    def _name(self, instance):\n        if instance.member:\n            return instance.member.profile.display_name()\n        return instance.name\n\n    def _photo(self, instance):\n        if instance.member and instance.member.profile.photo:\n            return self.context[\"request\"].build_absolute_uri(\n                f\"{settings.MEDIA_URL}{instance.member.profile.photo}\"\n            )\n        return self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n\n    def _avatar(self, instance):\n        placeholder = self.context[\"request\"].build_absolute_uri(\n            static(\"members/images/default-avatar.jpg\")\n        )\n        file = None\n        if instance.member and instance.member.profile.photo:\n            file = instance.member.profile.photo\n        return create_image_thumbnail_dict(\n            self.context[\"request\"], file, placeholder=placeholder, size_large=\"800x800\"\n        )\n\n    def __init__(self, instance=None, data=empty, **kwargs):\n        super().__init__(instance, data, **kwargs)\n        try:\n            if instance:\n                self.information_fields = services.registration_fields(\n                    kwargs[\"context\"][\"request\"], registration=instance\n                )\n        except RegistrationError:\n            pass\n\n    def get_fields(self):\n        fields = super().get_fields()\n\n        if self.information_fields:\n            for key, field in self.information_fields.items():\n                key = \"fields[{}]\".format(key)\n                field_type = field[\"type\"]\n\n                if field_type == RegistrationInformationField.BOOLEAN_FIELD:\n                    fields[key] = serializers.BooleanField(\n                        required=False, write_only=True\n                    )\n                elif field_type == RegistrationInformationField.INTEGER_FIELD:\n                    fields[key] = serializers.IntegerField(\n                        required=field[\"required\"],\n                        write_only=True,\n                        allow_null=not field[\"required\"],\n                    )\n                elif field_type == RegistrationInformationField.TEXT_FIELD:\n                    fields[key] = serializers.CharField(\n                        required=field[\"required\"],\n                        write_only=True,\n                        allow_blank=not field[\"required\"],\n                        allow_null=not field[\"required\"],\n                    )\n\n                fields[key].label = field[\"label\"]\n                fields[key].help_text = field[\"description\"]\n                fields[key].initial = field[\"value\"]\n                fields[key].default = field[\"value\"]\n\n                try:\n                    if key in self.information_fields:\n                        fields[key].initial = self.validated_data[key]\n                except AssertionError:\n                    pass\n\n        return fields\n\n    def to_representation(self, instance):\n        data = super().to_representation(instance)\n        data[\"fields\"] = self.information_fields\n        return data\n\n    def field_values(self):\n        return (\n            (name[7 : len(name) - 1], value)\n            for name, value in self.validated_data.items()\n            if \"info_field\" in name\n        )\n", "path": "website/events/api/v1/serializers/event_registrations/list.py"}]}