prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Fix adding avatar through api v2
  ### Describe the bug
  In api v1 the avatar can be set through `api/v1/members/me` with a multipart patch request with a file labelled `photo`. Api v2 should also allow this, but instead return 500.
  
  ### How to reproduce
  Send a request to patch the photo to api v1 and see that it works.
  Send the same request to api v2 and see the 500 response.
  
  Note that I have not tried editing anything else through api v2 yet, so it might be that some other fields also don't work.
  
  
  </issue>
  <code>
  [start of website/members/api/v2/serializers/member.py]
  1 from rest_framework import serializers
  2 
  3 from members.api.v2.serializers.profile import ProfileSerializer
  4 from members.models import Member
  5 from members.services import member_achievements, member_societies
  6 
  7 
  8 class MemberSerializer(serializers.ModelSerializer):
  9     def __init__(self, *args, **kwargs):
  10         # Don't pass the 'fields' arg up to the superclass
  11         detailed = kwargs.pop("detailed", True)
  12 
  13         # Instantiate the superclass normally
  14         super().__init__(*args, **kwargs)
  15 
  16         if not detailed:
  17             hidden_fields = {"achievements", "societies"}
  18             existing = set(self.fields.keys())
  19             for field_name in existing & hidden_fields:
  20                 self.fields.pop(field_name)
  21 
  22     class Meta:
  23         model = Member
  24         fields = ("pk", "membership_type", "profile", "achievements", "societies")
  25 
  26     membership_type = serializers.SerializerMethodField("_membership_type")
  27     profile = ProfileSerializer(
  28         fields=(
  29             "photo",
  30             "display_name",
  31             "short_display_name",
  32             "programme",
  33             "starting_year",
  34             "birthday",
  35             "website",
  36             "profile_description",
  37         )
  38     )
  39     achievements = serializers.SerializerMethodField("_achievements")
  40     societies = serializers.SerializerMethodField("_societies")
  41 
  42     def _achievements(self, instance):
  43         return member_achievements(instance)
  44 
  45     def _societies(self, instance):
  46         return member_societies(instance)
  47 
  48     def _membership_type(self, instance):
  49         membership = instance.current_membership
  50         if membership:
  51             return membership.type
  52         return None
  53 
  54     def update(self, instance, validated_data):
  55         profile_data = validated_data.pop("profile")
  56         instance.profile = self.fields["profile"].update(
  57             instance=instance.profile, validated_data=profile_data
  58         )
  59         return instance
  60 
  61 
  62 class MemberListSerializer(MemberSerializer):
  63     class Meta:
  64         model = Member
  65         fields = (
  66             "pk",
  67             "membership_type",
  68             "profile",
  69         )
  70 
  71 
  72 class MemberCurrentSerializer(MemberSerializer):
  73     class Meta:
  74         model = Member
  75         fields = ("pk", "membership_type", "profile", "achievements", "societies")
  76 
  77     profile = ProfileSerializer(
  78         fields=(
  79             "photo",
  80             "display_name",
  81             "short_display_name",
  82             "programme",
  83             "starting_year",
  84             "birthday",
  85             "show_birthday",
  86             "website",
  87             "profile_description",
  88             "address_street",
  89             "address_street2",
  90             "address_postal_code",
  91             "address_city",
  92             "address_country",
  93             "phone_number",
  94             "website",
  95             "emergency_contact",
  96             "emergency_contact_phone_number",
  97             "profile_description",
  98             "nickname",
  99             "initials",
  100             "display_name_preference",
  101             "receive_optin",
  102             "receive_newsletter",
  103             "receive_magazine",
  104             "email_gsuite_only",
  105         ),
  106         force_show_birthday=True,
  107     )
  108
  [end of website/members/api/v2/serializers/member.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/website/members/api/v2/serializers/member.py b/website/members/api/v2/serializers/member.py
  --- a/website/members/api/v2/serializers/member.py
  +++ b/website/members/api/v2/serializers/member.py
  @@ -1,4 +1,5 @@
   from rest_framework import serializers
  +from rest_framework.exceptions import ValidationError
   
   from members.api.v2.serializers.profile import ProfileSerializer
   from members.models import Member
  @@ -52,6 +53,9 @@
           return None
   
       def update(self, instance, validated_data):
  +        if "profile" not in validated_data:
  +            raise ValidationError("profile field is missing")
  +
           profile_data = validated_data.pop("profile")
           instance.profile = self.fields["profile"].update(
               instance=instance.profile, validated_data=profile_data
  
verification_info: {"golden_diff": "diff --git a/website/members/api/v2/serializers/member.py b/website/members/api/v2/serializers/member.py\n--- a/website/members/api/v2/serializers/member.py\n+++ b/website/members/api/v2/serializers/member.py\n@@ -1,4 +1,5 @@\n from rest_framework import serializers\n+from rest_framework.exceptions import ValidationError\n \n from members.api.v2.serializers.profile import ProfileSerializer\n from members.models import Member\n@@ -52,6 +53,9 @@\n         return None\n \n     def update(self, instance, validated_data):\n+        if \"profile\" not in validated_data:\n+            raise ValidationError(\"profile field is missing\")\n+\n         profile_data = validated_data.pop(\"profile\")\n         instance.profile = self.fields[\"profile\"].update(\n             instance=instance.profile, validated_data=profile_data\n", "issue": "Fix adding avatar through api v2\n### Describe the bug\r\nIn api v1 the avatar can be set through `api/v1/members/me` with a multipart patch request with a file labelled `photo`. Api v2 should also allow this, but instead return 500.\r\n\r\n### How to reproduce\r\nSend a request to patch the photo to api v1 and see that it works.\r\nSend the same request to api v2 and see the 500 response.\r\n\r\nNote that I have not tried editing anything else through api v2 yet, so it might be that some other fields also don't work.\r\n\n", "before_files": [{"content": "from rest_framework import serializers\n\nfrom members.api.v2.serializers.profile import ProfileSerializer\nfrom members.models import Member\nfrom members.services import member_achievements, member_societies\n\n\nclass MemberSerializer(serializers.ModelSerializer):\n    def __init__(self, *args, **kwargs):\n        # Don't pass the 'fields' arg up to the superclass\n        detailed = kwargs.pop(\"detailed\", True)\n\n        # Instantiate the superclass normally\n        super().__init__(*args, **kwargs)\n\n        if not detailed:\n            hidden_fields = {\"achievements\", \"societies\"}\n            existing = set(self.fields.keys())\n            for field_name in existing & hidden_fields:\n                self.fields.pop(field_name)\n\n    class Meta:\n        model = Member\n        fields = (\"pk\", \"membership_type\", \"profile\", \"achievements\", \"societies\")\n\n    membership_type = serializers.SerializerMethodField(\"_membership_type\")\n    profile = ProfileSerializer(\n        fields=(\n            \"photo\",\n            \"display_name\",\n            \"short_display_name\",\n            \"programme\",\n            \"starting_year\",\n            \"birthday\",\n            \"website\",\n            \"profile_description\",\n        )\n    )\n    achievements = serializers.SerializerMethodField(\"_achievements\")\n    societies = serializers.SerializerMethodField(\"_societies\")\n\n    def _achievements(self, instance):\n        return member_achievements(instance)\n\n    def _societies(self, instance):\n        return member_societies(instance)\n\n    def _membership_type(self, instance):\n        membership = instance.current_membership\n        if membership:\n            return membership.type\n        return None\n\n    def update(self, instance, validated_data):\n        profile_data = validated_data.pop(\"profile\")\n        instance.profile = self.fields[\"profile\"].update(\n            instance=instance.profile, validated_data=profile_data\n        )\n        return instance\n\n\nclass MemberListSerializer(MemberSerializer):\n    class Meta:\n        model = Member\n        fields = (\n            \"pk\",\n            \"membership_type\",\n            \"profile\",\n        )\n\n\nclass MemberCurrentSerializer(MemberSerializer):\n    class Meta:\n        model = Member\n        fields = (\"pk\", \"membership_type\", \"profile\", \"achievements\", \"societies\")\n\n    profile = ProfileSerializer(\n        fields=(\n            \"photo\",\n            \"display_name\",\n            \"short_display_name\",\n            \"programme\",\n            \"starting_year\",\n            \"birthday\",\n            \"show_birthday\",\n            \"website\",\n            \"profile_description\",\n            \"address_street\",\n            \"address_street2\",\n            \"address_postal_code\",\n            \"address_city\",\n            \"address_country\",\n            \"phone_number\",\n            \"website\",\n            \"emergency_contact\",\n            \"emergency_contact_phone_number\",\n            \"profile_description\",\n            \"nickname\",\n            \"initials\",\n            \"display_name_preference\",\n            \"receive_optin\",\n            \"receive_newsletter\",\n            \"receive_magazine\",\n            \"email_gsuite_only\",\n        ),\n        force_show_birthday=True,\n    )\n", "path": "website/members/api/v2/serializers/member.py"}]}