We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Project update endpoint gives internal server error
See `http://rsr.akvo.org/rest/v1/project_update/`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `akvo/rest/views/project_update.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """Akvo RSR is covered by the GNU Affero General Public License.
3 
4 See more details in the license.txt file located at the root folder of the Akvo RSR module.
5 For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
6 """
7 
8 from akvo.rsr.models import ProjectUpdate
9 
10 from ..serializers import ProjectUpdateSerializer, ProjectUpdateExtraSerializer
11 from ..viewsets import PublicProjectViewSet
12 
13 from rest_framework.decorators import api_view, permission_classes
14 from rest_framework.permissions import IsAuthenticated
15 from rest_framework.response import Response
16 
17 
18 class ProjectUpdateViewSet(PublicProjectViewSet):
19 
20     """."""
21     queryset = ProjectUpdate.objects.select_related('project',
22                                                     'user').prefetch_related('locations')
23     serializer_class = ProjectUpdateSerializer
24     filter_fields = {
25         'project': ['exact', ],
26         'indicator_period': ['exact', ],
27         'user': ['exact', ],
28         'uuid': ['exact', 'icontains', ],
29         'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],
30     }
31 
32     paginate_by_param = 'limit'
33     max_paginate_by = 1000
34 
35     def get_queryset(self):
36         """
37         Allow simple filtering on selected fields.
38         We don't use the default filter_fields, because Up filters on
39         datetime for last_modified_at, and they only support a date, not datetime.
40         """
41         created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)
42         if created_at__gt is not None:
43             self.queryset = self.queryset.filter(created_at__gt=created_at__gt)
44         created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)
45         if created_at__lt is not None:
46             self.queryset = self.queryset.filter(created_at__lt=created_at__lt)
47         last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)
48         if last_modified_at__gt is not None:
49             self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)
50         last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)
51         if last_modified_at__lt is not None:
52             self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)
53         # Get updates per organisation
54         project__partners = self.request.QUERY_PARAMS.get('project__partners', None)
55         if project__partners:
56             self.queryset = self.queryset.filter(project__partners=project__partners)
57         user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)
58         if user__organisations:
59             self.queryset = self.queryset.filter(user__organisations=user__organisations)
60         return super(ProjectUpdateViewSet, self).get_queryset()
61 
62 
63 class ProjectUpdateExtraViewSet(PublicProjectViewSet):
64 
65     """Project update extra resource."""
66 
67     max_paginate_by = 30
68     paginate_by = 10
69 
70     queryset = ProjectUpdate.objects.select_related(
71         'primary_location',
72         'primary_location__location_target',
73         'primary_location__location_target__project',
74         'primary_location__location_target__user',
75         'primary_location__location_target__primary_location',
76         'primary_location__location_target__country',
77         'project',
78         'user',
79         'user__organisation',
80         'user__organisation__primary_location',
81         'user__organisation__primary_location__country',
82         'user__organisation__primary_location__location_target',
83         'user__organisation__primary_location__location_target__internal_org_ids',
84 
85     ).prefetch_related(
86         'user__organisations',
87         'user__organisations__primary_location',
88         'user__organisations__primary_location__country',
89         'user__organisations__primary_location__location_target')
90     serializer_class = ProjectUpdateExtraSerializer
91     filter_fields = {
92         'project': ['exact', ],
93         'indicator_period': ['exact', ],
94         'user': ['exact', ],
95         'uuid': ['exact', 'icontains', ],
96         'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],
97         # These filters only accept a date, not a datetime
98         # 'created_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],
99         # 'last_modified_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],
100     }
101 
102     def get_queryset(self):
103         """
104         Allow simple filtering on selected fields.
105         We don't use the default filter_fields, because Up filters on
106         datetime for last_modified_at, and they only support a date, not datetime.
107         """
108         created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)
109         if created_at__gt is not None:
110             self.queryset = self.queryset.filter(created_at__gt=created_at__gt)
111         created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)
112         if created_at__lt is not None:
113             self.queryset = self.queryset.filter(created_at__lt=created_at__lt)
114         last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)
115         if last_modified_at__gt is not None:
116             self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)
117         last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)
118         if last_modified_at__lt is not None:
119             self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)
120         # Get updates per organisation
121         project__partners = self.request.QUERY_PARAMS.get('project__partners', None)
122         if project__partners:
123             self.queryset = self.queryset.filter(project__partners=project__partners)
124         user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)
125         if user__organisations:
126             self.queryset = self.queryset.filter(user__organisations=user__organisations)
127         return super(ProjectUpdateExtraViewSet, self).get_queryset()
128 
129 
130 @api_view(['POST'])
131 @permission_classes((IsAuthenticated, ))
132 def upload_indicator_update_photo(request, pk=None):
133     update = ProjectUpdate.objects.get(pk=pk)
134     user = request.user
135 
136     # TODO: permissions
137 
138     files = request.FILES
139 
140     if 'photo' in files.keys():
141         update.photo = files['photo']
142         update.save(update_fields=['photo'])
143 
144     return Response(ProjectUpdateExtraSerializer(update).data)
145
```
--- 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/akvo/rest/views/project_update.py b/akvo/rest/views/project_update.py
--- a/akvo/rest/views/project_update.py
+++ b/akvo/rest/views/project_update.py
@@ -23,10 +23,8 @@
     serializer_class = ProjectUpdateSerializer
     filter_fields = {
         'project': ['exact', ],
-        'indicator_period': ['exact', ],
         'user': ['exact', ],
         'uuid': ['exact', 'icontains', ],
-        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],
     }
 
     paginate_by_param = 'limit'
@@ -90,10 +88,8 @@
     serializer_class = ProjectUpdateExtraSerializer
     filter_fields = {
         'project': ['exact', ],
-        'indicator_period': ['exact', ],
         'user': ['exact', ],
         'uuid': ['exact', 'icontains', ],
-        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],
         # These filters only accept a date, not a datetime
         # 'created_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],
         # 'last_modified_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],

{"golden_diff": "diff --git a/akvo/rest/views/project_update.py b/akvo/rest/views/project_update.py\n--- a/akvo/rest/views/project_update.py\n+++ b/akvo/rest/views/project_update.py\n@@ -23,10 +23,8 @@\n     serializer_class = ProjectUpdateSerializer\n     filter_fields = {\n         'project': ['exact', ],\n-        'indicator_period': ['exact', ],\n         'user': ['exact', ],\n         'uuid': ['exact', 'icontains', ],\n-        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n     }\n \n     paginate_by_param = 'limit'\n@@ -90,10 +88,8 @@\n     serializer_class = ProjectUpdateExtraSerializer\n     filter_fields = {\n         'project': ['exact', ],\n-        'indicator_period': ['exact', ],\n         'user': ['exact', ],\n         'uuid': ['exact', 'icontains', ],\n-        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n         # These filters only accept a date, not a datetime\n         # 'created_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n         # 'last_modified_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n", "issue": "Project update endpoint gives internal server error\nSee `http://rsr.akvo.org/rest/v1/project_update/`\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import ProjectUpdate\n\nfrom ..serializers import ProjectUpdateSerializer, ProjectUpdateExtraSerializer\nfrom ..viewsets import PublicProjectViewSet\n\nfrom rest_framework.decorators import api_view, permission_classes\nfrom rest_framework.permissions import IsAuthenticated\nfrom rest_framework.response import Response\n\n\nclass ProjectUpdateViewSet(PublicProjectViewSet):\n\n    \"\"\".\"\"\"\n    queryset = ProjectUpdate.objects.select_related('project',\n                                                    'user').prefetch_related('locations')\n    serializer_class = ProjectUpdateSerializer\n    filter_fields = {\n        'project': ['exact', ],\n        'indicator_period': ['exact', ],\n        'user': ['exact', ],\n        'uuid': ['exact', 'icontains', ],\n        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n    }\n\n    paginate_by_param = 'limit'\n    max_paginate_by = 1000\n\n    def get_queryset(self):\n        \"\"\"\n        Allow simple filtering on selected fields.\n        We don't use the default filter_fields, because Up filters on\n        datetime for last_modified_at, and they only support a date, not datetime.\n        \"\"\"\n        created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)\n        if created_at__gt is not None:\n            self.queryset = self.queryset.filter(created_at__gt=created_at__gt)\n        created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)\n        if created_at__lt is not None:\n            self.queryset = self.queryset.filter(created_at__lt=created_at__lt)\n        last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)\n        if last_modified_at__gt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)\n        last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)\n        if last_modified_at__lt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)\n        # Get updates per organisation\n        project__partners = self.request.QUERY_PARAMS.get('project__partners', None)\n        if project__partners:\n            self.queryset = self.queryset.filter(project__partners=project__partners)\n        user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)\n        if user__organisations:\n            self.queryset = self.queryset.filter(user__organisations=user__organisations)\n        return super(ProjectUpdateViewSet, self).get_queryset()\n\n\nclass ProjectUpdateExtraViewSet(PublicProjectViewSet):\n\n    \"\"\"Project update extra resource.\"\"\"\n\n    max_paginate_by = 30\n    paginate_by = 10\n\n    queryset = ProjectUpdate.objects.select_related(\n        'primary_location',\n        'primary_location__location_target',\n        'primary_location__location_target__project',\n        'primary_location__location_target__user',\n        'primary_location__location_target__primary_location',\n        'primary_location__location_target__country',\n        'project',\n        'user',\n        'user__organisation',\n        'user__organisation__primary_location',\n        'user__organisation__primary_location__country',\n        'user__organisation__primary_location__location_target',\n        'user__organisation__primary_location__location_target__internal_org_ids',\n\n    ).prefetch_related(\n        'user__organisations',\n        'user__organisations__primary_location',\n        'user__organisations__primary_location__country',\n        'user__organisations__primary_location__location_target')\n    serializer_class = ProjectUpdateExtraSerializer\n    filter_fields = {\n        'project': ['exact', ],\n        'indicator_period': ['exact', ],\n        'user': ['exact', ],\n        'uuid': ['exact', 'icontains', ],\n        'period_update': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n        # These filters only accept a date, not a datetime\n        # 'created_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n        # 'last_modified_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n    }\n\n    def get_queryset(self):\n        \"\"\"\n        Allow simple filtering on selected fields.\n        We don't use the default filter_fields, because Up filters on\n        datetime for last_modified_at, and they only support a date, not datetime.\n        \"\"\"\n        created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)\n        if created_at__gt is not None:\n            self.queryset = self.queryset.filter(created_at__gt=created_at__gt)\n        created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)\n        if created_at__lt is not None:\n            self.queryset = self.queryset.filter(created_at__lt=created_at__lt)\n        last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)\n        if last_modified_at__gt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)\n        last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)\n        if last_modified_at__lt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)\n        # Get updates per organisation\n        project__partners = self.request.QUERY_PARAMS.get('project__partners', None)\n        if project__partners:\n            self.queryset = self.queryset.filter(project__partners=project__partners)\n        user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)\n        if user__organisations:\n            self.queryset = self.queryset.filter(user__organisations=user__organisations)\n        return super(ProjectUpdateExtraViewSet, self).get_queryset()\n\n\n@api_view(['POST'])\n@permission_classes((IsAuthenticated, ))\ndef upload_indicator_update_photo(request, pk=None):\n    update = ProjectUpdate.objects.get(pk=pk)\n    user = request.user\n\n    # TODO: permissions\n\n    files = request.FILES\n\n    if 'photo' in files.keys():\n        update.photo = files['photo']\n        update.save(update_fields=['photo'])\n\n    return Response(ProjectUpdateExtraSerializer(update).data)\n", "path": "akvo/rest/views/project_update.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import ProjectUpdate\n\nfrom ..serializers import ProjectUpdateSerializer, ProjectUpdateExtraSerializer\nfrom ..viewsets import PublicProjectViewSet\n\nfrom rest_framework.decorators import api_view, permission_classes\nfrom rest_framework.permissions import IsAuthenticated\nfrom rest_framework.response import Response\n\n\nclass ProjectUpdateViewSet(PublicProjectViewSet):\n\n    \"\"\".\"\"\"\n    queryset = ProjectUpdate.objects.select_related('project',\n                                                    'user').prefetch_related('locations')\n    serializer_class = ProjectUpdateSerializer\n    filter_fields = {\n        'project': ['exact', ],\n        'user': ['exact', ],\n        'uuid': ['exact', 'icontains', ],\n    }\n\n    paginate_by_param = 'limit'\n    max_paginate_by = 1000\n\n    def get_queryset(self):\n        \"\"\"\n        Allow simple filtering on selected fields.\n        We don't use the default filter_fields, because Up filters on\n        datetime for last_modified_at, and they only support a date, not datetime.\n        \"\"\"\n        created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)\n        if created_at__gt is not None:\n            self.queryset = self.queryset.filter(created_at__gt=created_at__gt)\n        created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)\n        if created_at__lt is not None:\n            self.queryset = self.queryset.filter(created_at__lt=created_at__lt)\n        last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)\n        if last_modified_at__gt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)\n        last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)\n        if last_modified_at__lt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)\n        # Get updates per organisation\n        project__partners = self.request.QUERY_PARAMS.get('project__partners', None)\n        if project__partners:\n            self.queryset = self.queryset.filter(project__partners=project__partners)\n        user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)\n        if user__organisations:\n            self.queryset = self.queryset.filter(user__organisations=user__organisations)\n        return super(ProjectUpdateViewSet, self).get_queryset()\n\n\nclass ProjectUpdateExtraViewSet(PublicProjectViewSet):\n\n    \"\"\"Project update extra resource.\"\"\"\n\n    max_paginate_by = 30\n    paginate_by = 10\n\n    queryset = ProjectUpdate.objects.select_related(\n        'primary_location',\n        'primary_location__location_target',\n        'primary_location__location_target__project',\n        'primary_location__location_target__user',\n        'primary_location__location_target__primary_location',\n        'primary_location__location_target__country',\n        'project',\n        'user',\n        'user__organisation',\n        'user__organisation__primary_location',\n        'user__organisation__primary_location__country',\n        'user__organisation__primary_location__location_target',\n        'user__organisation__primary_location__location_target__internal_org_ids',\n\n    ).prefetch_related(\n        'user__organisations',\n        'user__organisations__primary_location',\n        'user__organisations__primary_location__country',\n        'user__organisations__primary_location__location_target')\n    serializer_class = ProjectUpdateExtraSerializer\n    filter_fields = {\n        'project': ['exact', ],\n        'user': ['exact', ],\n        'uuid': ['exact', 'icontains', ],\n        # These filters only accept a date, not a datetime\n        # 'created_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n        # 'last_modified_at': ['exact', 'gt', 'gte', 'lt', 'lte', ],\n    }\n\n    def get_queryset(self):\n        \"\"\"\n        Allow simple filtering on selected fields.\n        We don't use the default filter_fields, because Up filters on\n        datetime for last_modified_at, and they only support a date, not datetime.\n        \"\"\"\n        created_at__gt = self.request.QUERY_PARAMS.get('created_at__gt', None)\n        if created_at__gt is not None:\n            self.queryset = self.queryset.filter(created_at__gt=created_at__gt)\n        created_at__lt = self.request.QUERY_PARAMS.get('created_at__lt', None)\n        if created_at__lt is not None:\n            self.queryset = self.queryset.filter(created_at__lt=created_at__lt)\n        last_modified_at__gt = self.request.QUERY_PARAMS.get('last_modified_at__gt', None)\n        if last_modified_at__gt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__gt=last_modified_at__gt)\n        last_modified_at__lt = self.request.QUERY_PARAMS.get('last_modified_at__lt', None)\n        if last_modified_at__lt is not None:\n            self.queryset = self.queryset.filter(last_modified_at__lt=last_modified_at__lt)\n        # Get updates per organisation\n        project__partners = self.request.QUERY_PARAMS.get('project__partners', None)\n        if project__partners:\n            self.queryset = self.queryset.filter(project__partners=project__partners)\n        user__organisations = self.request.QUERY_PARAMS.get('user__organisations', None)\n        if user__organisations:\n            self.queryset = self.queryset.filter(user__organisations=user__organisations)\n        return super(ProjectUpdateExtraViewSet, self).get_queryset()\n\n\n@api_view(['POST'])\n@permission_classes((IsAuthenticated, ))\ndef upload_indicator_update_photo(request, pk=None):\n    update = ProjectUpdate.objects.get(pk=pk)\n    user = request.user\n\n    # TODO: permissions\n\n    files = request.FILES\n\n    if 'photo' in files.keys():\n        update.photo = files['photo']\n        update.save(update_fields=['photo'])\n\n    return Response(ProjectUpdateExtraSerializer(update).data)\n", "path": "akvo/rest/views/project_update.py"}]}