prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  timetable/data/departments endpoint returns 500 error
  The timetable/data/departments endpoint is currently returning a 500 error on any request.
  
  I know it's not a documented endpoint, but it would be nice if it worked :)
  
  It looks to me like the problem is line 85 below - `rate_limiting_data` is being passed as an argument to `append`. 
  
  https://github.com/uclapi/uclapi/blob/cfd6753ae3d979bbe53573dad68babc2de19e04d/backend/uclapi/timetable/views.py#L82-L85
  
  Removing that and replacing with this:
  ```python
  depts["departments"].append({ 
  "department_id": dept.deptid, 
  "name": dept.name}) 
  ```
  should fix it, though I don't have the whole API setup installed, so I can't be sure.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `backend/uclapi/timetable/views.py`
  Content:
  ```
  1 from django.conf import settings
  2 
  3 from rest_framework.decorators import api_view
  4 
  5 from common.helpers import PrettyJsonResponse as JsonResponse
  6 
  7 from .models import Lock, Course, Depts, ModuleA, ModuleB
  8 
  9 from .app_helpers import get_student_timetable, get_custom_timetable
  10 
  11 from common.decorators import uclapi_protected_endpoint
  12 
  13 _SETID = settings.ROOMBOOKINGS_SETID
  14 
  15 
  16 @api_view(["GET"])
  17 @uclapi_protected_endpoint(personal_data=True, required_scopes=['timetable'])
  18 def get_personal_timetable(request, *args, **kwargs):
  19     token = kwargs['token']
  20     user = token.user
  21     try:
  22         date_filter = request.GET["date_filter"]
  23         timetable = get_student_timetable(user.employee_id, date_filter)
  24     except KeyError:
  25         timetable = get_student_timetable(user.employee_id)
  26 
  27     response = {
  28         "ok": True,
  29         "timetable": timetable
  30     }
  31     return JsonResponse(response, rate_limiting_data=kwargs)
  32 
  33 
  34 @api_view(["GET"])
  35 @uclapi_protected_endpoint()
  36 def get_modules_timetable(request, *args, **kwargs):
  37     module_ids = request.GET.get("modules")
  38     if module_ids is None:
  39         return JsonResponse({
  40             "ok": False,
  41             "error": "No module IDs provided."
  42         }, rate_limiting_data=kwargs)
  43 
  44     try:
  45         modules = module_ids.split(',')
  46     except ValueError:
  47         return JsonResponse({
  48             "ok": False,
  49             "error": "Invalid module IDs provided."
  50         }, rate_limiting_data=kwargs)
  51 
  52     try:
  53         date_filter = request.GET["date_filter"]
  54         custom_timetable = get_custom_timetable(modules, date_filter)
  55     except KeyError:
  56         custom_timetable = get_custom_timetable(modules)
  57 
  58     if custom_timetable:
  59         response_json = {
  60             "ok": True,
  61             "timetable": custom_timetable
  62         }
  63         return JsonResponse(response_json, rate_limiting_data=kwargs)
  64     else:
  65         response_json = {
  66             "ok": False,
  67             "error": "One or more invalid Module IDs supplied."
  68         }
  69         response = JsonResponse(response_json, rate_limiting_data=kwargs)
  70         response.status_code = 400
  71         return response
  72 
  73 
  74 @api_view(["GET"])
  75 @uclapi_protected_endpoint()
  76 def get_departments(request, *args, **kwargs):
  77     """
  78     Returns all departments at UCL
  79     """
  80     depts = {"ok": True, "departments": []}
  81     for dept in Depts.objects.all():
  82         depts["departments"].append({
  83             "department_id": dept.deptid,
  84             "name": dept.name
  85         }, rate_limiting_data=kwargs)
  86     return JsonResponse(depts, rate_limiting_data=kwargs)
  87 
  88 
  89 @api_view(["GET"])
  90 @uclapi_protected_endpoint()
  91 def get_department_courses(request, *args, **kwargs):
  92     """
  93     Returns all the courses in UCL with relevant ID
  94     """
  95     try:
  96         department_id = request.GET["department"]
  97     except KeyError:
  98         response = JsonResponse({
  99             "ok": False,
  100             "error": "Supply a Department ID using the department parameter."
  101         }, rate_limiting_data=kwargs)
  102         response.status_code = 400
  103         return response
  104 
  105     courses = {"ok": True, "courses": []}
  106     for course in Course.objects.filter(owner=department_id, setid=_SETID):
  107         courses["courses"].append({
  108             "course_name": course.name,
  109             "course_id": course.courseid,
  110             "years": course.numyears
  111         })
  112     return JsonResponse(courses, rate_limiting_data=kwargs)
  113 
  114 
  115 @api_view(["GET"])
  116 @uclapi_protected_endpoint()
  117 def get_department_modules(request, *args, **kwargs):
  118     """
  119     Returns all modules taught by a particular department.
  120     """
  121     try:
  122         department_id = request.GET["department"]
  123     except KeyError:
  124         response = JsonResponse({
  125             "ok": False,
  126             "error": "Supply a Department ID using the department parameter."
  127         }, rate_limiting_data=kwargs)
  128         response.status_code = 400
  129         return response
  130 
  131     modules = {"ok": True, "modules": []}
  132     lock = Lock.objects.all()[0]
  133     m = ModuleA if lock.a else ModuleB
  134     for module in m.objects.filter(owner=department_id, setid=_SETID):
  135         modules["modules"].append({
  136             "module_id": module.moduleid,
  137             "name": module.name,
  138             "module_code": module.linkcode,
  139             "class_size": module.csize
  140         })
  141 
  142     return JsonResponse(modules, rate_limiting_data=kwargs)
  143
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/backend/uclapi/timetable/views.py b/backend/uclapi/timetable/views.py
  --- a/backend/uclapi/timetable/views.py
  +++ b/backend/uclapi/timetable/views.py
  @@ -82,7 +82,7 @@
           depts["departments"].append({
               "department_id": dept.deptid,
               "name": dept.name
  -        }, rate_limiting_data=kwargs)
  +        })
       return JsonResponse(depts, rate_limiting_data=kwargs)
  
verification_info: {"golden_diff": "diff --git a/backend/uclapi/timetable/views.py b/backend/uclapi/timetable/views.py\n--- a/backend/uclapi/timetable/views.py\n+++ b/backend/uclapi/timetable/views.py\n@@ -82,7 +82,7 @@\n         depts[\"departments\"].append({\n             \"department_id\": dept.deptid,\n             \"name\": dept.name\n-        }, rate_limiting_data=kwargs)\n+        })\n     return JsonResponse(depts, rate_limiting_data=kwargs)\n", "issue": "timetable/data/departments endpoint returns 500 error\nThe timetable/data/departments endpoint is currently returning a 500 error on any request.\r\n\r\nI know it's not a documented endpoint, but it would be nice if it worked :)\r\n\r\nIt looks to me like the problem is line 85 below - `rate_limiting_data` is being passed as an argument to `append`. \r\n\r\nhttps://github.com/uclapi/uclapi/blob/cfd6753ae3d979bbe53573dad68babc2de19e04d/backend/uclapi/timetable/views.py#L82-L85\r\n\r\nRemoving that and replacing with this:\r\n```python\r\ndepts[\"departments\"].append({ \r\n\"department_id\": dept.deptid, \r\n\"name\": dept.name}) \r\n```\r\nshould fix it, though I don't have the whole API setup installed, so I can't be sure.\n", "before_files": [{"content": "from django.conf import settings\n\nfrom rest_framework.decorators import api_view\n\nfrom common.helpers import PrettyJsonResponse as JsonResponse\n\nfrom .models import Lock, Course, Depts, ModuleA, ModuleB\n\nfrom .app_helpers import get_student_timetable, get_custom_timetable\n\nfrom common.decorators import uclapi_protected_endpoint\n\n_SETID = settings.ROOMBOOKINGS_SETID\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint(personal_data=True, required_scopes=['timetable'])\ndef get_personal_timetable(request, *args, **kwargs):\n    token = kwargs['token']\n    user = token.user\n    try:\n        date_filter = request.GET[\"date_filter\"]\n        timetable = get_student_timetable(user.employee_id, date_filter)\n    except KeyError:\n        timetable = get_student_timetable(user.employee_id)\n\n    response = {\n        \"ok\": True,\n        \"timetable\": timetable\n    }\n    return JsonResponse(response, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_modules_timetable(request, *args, **kwargs):\n    module_ids = request.GET.get(\"modules\")\n    if module_ids is None:\n        return JsonResponse({\n            \"ok\": False,\n            \"error\": \"No module IDs provided.\"\n        }, rate_limiting_data=kwargs)\n\n    try:\n        modules = module_ids.split(',')\n    except ValueError:\n        return JsonResponse({\n            \"ok\": False,\n            \"error\": \"Invalid module IDs provided.\"\n        }, rate_limiting_data=kwargs)\n\n    try:\n        date_filter = request.GET[\"date_filter\"]\n        custom_timetable = get_custom_timetable(modules, date_filter)\n    except KeyError:\n        custom_timetable = get_custom_timetable(modules)\n\n    if custom_timetable:\n        response_json = {\n            \"ok\": True,\n            \"timetable\": custom_timetable\n        }\n        return JsonResponse(response_json, rate_limiting_data=kwargs)\n    else:\n        response_json = {\n            \"ok\": False,\n            \"error\": \"One or more invalid Module IDs supplied.\"\n        }\n        response = JsonResponse(response_json, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_departments(request, *args, **kwargs):\n    \"\"\"\n    Returns all departments at UCL\n    \"\"\"\n    depts = {\"ok\": True, \"departments\": []}\n    for dept in Depts.objects.all():\n        depts[\"departments\"].append({\n            \"department_id\": dept.deptid,\n            \"name\": dept.name\n        }, rate_limiting_data=kwargs)\n    return JsonResponse(depts, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_department_courses(request, *args, **kwargs):\n    \"\"\"\n    Returns all the courses in UCL with relevant ID\n    \"\"\"\n    try:\n        department_id = request.GET[\"department\"]\n    except KeyError:\n        response = JsonResponse({\n            \"ok\": False,\n            \"error\": \"Supply a Department ID using the department parameter.\"\n        }, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n    courses = {\"ok\": True, \"courses\": []}\n    for course in Course.objects.filter(owner=department_id, setid=_SETID):\n        courses[\"courses\"].append({\n            \"course_name\": course.name,\n            \"course_id\": course.courseid,\n            \"years\": course.numyears\n        })\n    return JsonResponse(courses, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_department_modules(request, *args, **kwargs):\n    \"\"\"\n    Returns all modules taught by a particular department.\n    \"\"\"\n    try:\n        department_id = request.GET[\"department\"]\n    except KeyError:\n        response = JsonResponse({\n            \"ok\": False,\n            \"error\": \"Supply a Department ID using the department parameter.\"\n        }, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n    modules = {\"ok\": True, \"modules\": []}\n    lock = Lock.objects.all()[0]\n    m = ModuleA if lock.a else ModuleB\n    for module in m.objects.filter(owner=department_id, setid=_SETID):\n        modules[\"modules\"].append({\n            \"module_id\": module.moduleid,\n            \"name\": module.name,\n            \"module_code\": module.linkcode,\n            \"class_size\": module.csize\n        })\n\n    return JsonResponse(modules, rate_limiting_data=kwargs)\n", "path": "backend/uclapi/timetable/views.py"}], "after_files": [{"content": "from django.conf import settings\n\nfrom rest_framework.decorators import api_view\n\nfrom common.helpers import PrettyJsonResponse as JsonResponse\n\nfrom .models import Lock, Course, Depts, ModuleA, ModuleB\n\nfrom .app_helpers import get_student_timetable, get_custom_timetable\n\nfrom common.decorators import uclapi_protected_endpoint\n\n_SETID = settings.ROOMBOOKINGS_SETID\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint(personal_data=True, required_scopes=['timetable'])\ndef get_personal_timetable(request, *args, **kwargs):\n    token = kwargs['token']\n    user = token.user\n    try:\n        date_filter = request.GET[\"date_filter\"]\n        timetable = get_student_timetable(user.employee_id, date_filter)\n    except KeyError:\n        timetable = get_student_timetable(user.employee_id)\n\n    response = {\n        \"ok\": True,\n        \"timetable\": timetable\n    }\n    return JsonResponse(response, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_modules_timetable(request, *args, **kwargs):\n    module_ids = request.GET.get(\"modules\")\n    if module_ids is None:\n        return JsonResponse({\n            \"ok\": False,\n            \"error\": \"No module IDs provided.\"\n        }, rate_limiting_data=kwargs)\n\n    try:\n        modules = module_ids.split(',')\n    except ValueError:\n        return JsonResponse({\n            \"ok\": False,\n            \"error\": \"Invalid module IDs provided.\"\n        }, rate_limiting_data=kwargs)\n\n    try:\n        date_filter = request.GET[\"date_filter\"]\n        custom_timetable = get_custom_timetable(modules, date_filter)\n    except KeyError:\n        custom_timetable = get_custom_timetable(modules)\n\n    if custom_timetable:\n        response_json = {\n            \"ok\": True,\n            \"timetable\": custom_timetable\n        }\n        return JsonResponse(response_json, rate_limiting_data=kwargs)\n    else:\n        response_json = {\n            \"ok\": False,\n            \"error\": \"One or more invalid Module IDs supplied.\"\n        }\n        response = JsonResponse(response_json, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_departments(request, *args, **kwargs):\n    \"\"\"\n    Returns all departments at UCL\n    \"\"\"\n    depts = {\"ok\": True, \"departments\": []}\n    for dept in Depts.objects.all():\n        depts[\"departments\"].append({\n            \"department_id\": dept.deptid,\n            \"name\": dept.name\n        })\n    return JsonResponse(depts, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_department_courses(request, *args, **kwargs):\n    \"\"\"\n    Returns all the courses in UCL with relevant ID\n    \"\"\"\n    try:\n        department_id = request.GET[\"department\"]\n    except KeyError:\n        response = JsonResponse({\n            \"ok\": False,\n            \"error\": \"Supply a Department ID using the department parameter.\"\n        }, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n    courses = {\"ok\": True, \"courses\": []}\n    for course in Course.objects.filter(owner=department_id, setid=_SETID):\n        courses[\"courses\"].append({\n            \"course_name\": course.name,\n            \"course_id\": course.courseid,\n            \"years\": course.numyears\n        })\n    return JsonResponse(courses, rate_limiting_data=kwargs)\n\n\n@api_view([\"GET\"])\n@uclapi_protected_endpoint()\ndef get_department_modules(request, *args, **kwargs):\n    \"\"\"\n    Returns all modules taught by a particular department.\n    \"\"\"\n    try:\n        department_id = request.GET[\"department\"]\n    except KeyError:\n        response = JsonResponse({\n            \"ok\": False,\n            \"error\": \"Supply a Department ID using the department parameter.\"\n        }, rate_limiting_data=kwargs)\n        response.status_code = 400\n        return response\n\n    modules = {\"ok\": True, \"modules\": []}\n    lock = Lock.objects.all()[0]\n    m = ModuleA if lock.a else ModuleB\n    for module in m.objects.filter(owner=department_id, setid=_SETID):\n        modules[\"modules\"].append({\n            \"module_id\": module.moduleid,\n            \"name\": module.name,\n            \"module_code\": module.linkcode,\n            \"class_size\": module.csize\n        })\n\n    return JsonResponse(modules, rate_limiting_data=kwargs)\n", "path": "backend/uclapi/timetable/views.py"}]}