We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Empty and null prerequisites can be added from admin UI
**Environment**:

- CTFd Version/Commit: 843546b (tip of master)
- Operating System: Linux
- Web Browser and Version: Firefox

**What happened?**
Adding a prerequisite to a challenge without selecting a valid challenge entry in the drop down results in either `""` (selecting the "--" item in the drop down) or `null` (not selecting anything in the dropdown). This also breaks rendering of any previously added prerequisites when the UI is reloaded.

**What did you expect to happen?**
The backend should reject invalid prerequisites (probably via the `ChallengeSchema`?) and the frontend also shouldn't make it easy to submit them.

**How to reproduce your issue**
1. Create two challenges A and B
2. VIsit the admin UI page to edit B and click on the "Requirements" tab
3. Select A in the dropdown and click "Add Prerequisite"
4. Select the "--" entry in the dropdown and click "Add Prerequisite" again - observe rendering breakage
5. Solve A in either user or teams mode
6. Query `/api/v1/challenges` and observe that B is not present
7. Visit the admin UI again and select nothing in the requirements dropdown (it will remain blank), then click "Add Prerequisite" once more
8. Check the requirements for the B in the DB/from the ORM. They will be `[<ID of A>, "", None]`

**Any associated stack traces or error logs**


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `CTFd/schemas/challenges.py`
Content:
```
1 from marshmallow import validate
2 from marshmallow_sqlalchemy import field_for
3 
4 from CTFd.models import Challenges, ma
5 
6 
7 class ChallengeSchema(ma.ModelSchema):
8     class Meta:
9         model = Challenges
10         include_fk = True
11         dump_only = ("id",)
12 
13     name = field_for(
14         Challenges,
15         "name",
16         validate=[
17             validate.Length(
18                 min=0,
19                 max=80,
20                 error="Challenge could not be saved. Challenge name too long",
21             )
22         ],
23     )
24 
25     category = field_for(
26         Challenges,
27         "category",
28         validate=[
29             validate.Length(
30                 min=0,
31                 max=80,
32                 error="Challenge could not be saved. Challenge category too long",
33             )
34         ],
35     )
36 
37     description = field_for(
38         Challenges,
39         "description",
40         allow_none=True,
41         validate=[
42             validate.Length(
43                 min=0,
44                 max=65535,
45                 error="Challenge could not be saved. Challenge description too long",
46             )
47         ],
48     )
49
```
--- 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/CTFd/schemas/challenges.py b/CTFd/schemas/challenges.py
--- a/CTFd/schemas/challenges.py
+++ b/CTFd/schemas/challenges.py
@@ -1,9 +1,29 @@
 from marshmallow import validate
+from marshmallow.exceptions import ValidationError
 from marshmallow_sqlalchemy import field_for
 
 from CTFd.models import Challenges, ma
 
 
+class ChallengeRequirementsValidator(validate.Validator):
+    default_message = "Error parsing challenge requirements"
+
+    def __init__(self, error=None):
+        self.error = error or self.default_message
+
+    def __call__(self, value):
+        if isinstance(value, dict) is False:
+            raise ValidationError(self.default_message)
+
+        prereqs = value.get("prerequisites", [])
+        if all(prereqs) is False:
+            raise ValidationError(
+                "Challenge requirements cannot have a null prerequisite"
+            )
+
+        return value
+
+
 class ChallengeSchema(ma.ModelSchema):
     class Meta:
         model = Challenges
@@ -46,3 +66,7 @@
             )
         ],
     )
+
+    requirements = field_for(
+        Challenges, "requirements", validate=[ChallengeRequirementsValidator()],
+    )

{"golden_diff": "diff --git a/CTFd/schemas/challenges.py b/CTFd/schemas/challenges.py\n--- a/CTFd/schemas/challenges.py\n+++ b/CTFd/schemas/challenges.py\n@@ -1,9 +1,29 @@\n from marshmallow import validate\n+from marshmallow.exceptions import ValidationError\n from marshmallow_sqlalchemy import field_for\n \n from CTFd.models import Challenges, ma\n \n \n+class ChallengeRequirementsValidator(validate.Validator):\n+    default_message = \"Error parsing challenge requirements\"\n+\n+    def __init__(self, error=None):\n+        self.error = error or self.default_message\n+\n+    def __call__(self, value):\n+        if isinstance(value, dict) is False:\n+            raise ValidationError(self.default_message)\n+\n+        prereqs = value.get(\"prerequisites\", [])\n+        if all(prereqs) is False:\n+            raise ValidationError(\n+                \"Challenge requirements cannot have a null prerequisite\"\n+            )\n+\n+        return value\n+\n+\n class ChallengeSchema(ma.ModelSchema):\n     class Meta:\n         model = Challenges\n@@ -46,3 +66,7 @@\n             )\n         ],\n     )\n+\n+    requirements = field_for(\n+        Challenges, \"requirements\", validate=[ChallengeRequirementsValidator()],\n+    )\n", "issue": "Empty and null prerequisites can be added from admin UI\n**Environment**:\r\n\r\n- CTFd Version/Commit: 843546b (tip of master)\r\n- Operating System: Linux\r\n- Web Browser and Version: Firefox\r\n\r\n**What happened?**\r\nAdding a prerequisite to a challenge without selecting a valid challenge entry in the drop down results in either `\"\"` (selecting the \"--\" item in the drop down) or `null` (not selecting anything in the dropdown). This also breaks rendering of any previously added prerequisites when the UI is reloaded.\r\n\r\n**What did you expect to happen?**\r\nThe backend should reject invalid prerequisites (probably via the `ChallengeSchema`?) and the frontend also shouldn't make it easy to submit them.\r\n\r\n**How to reproduce your issue**\r\n1. Create two challenges A and B\r\n2. VIsit the admin UI page to edit B and click on the \"Requirements\" tab\r\n3. Select A in the dropdown and click \"Add Prerequisite\"\r\n4. Select the \"--\" entry in the dropdown and click \"Add Prerequisite\" again - observe rendering breakage\r\n5. Solve A in either user or teams mode\r\n6. Query `/api/v1/challenges` and observe that B is not present\r\n7. Visit the admin UI again and select nothing in the requirements dropdown (it will remain blank), then click \"Add Prerequisite\" once more\r\n8. Check the requirements for the B in the DB/from the ORM. They will be `[<ID of A>, \"\", None]`\r\n\r\n**Any associated stack traces or error logs**\r\n\n", "before_files": [{"content": "from marshmallow import validate\nfrom marshmallow_sqlalchemy import field_for\n\nfrom CTFd.models import Challenges, ma\n\n\nclass ChallengeSchema(ma.ModelSchema):\n    class Meta:\n        model = Challenges\n        include_fk = True\n        dump_only = (\"id\",)\n\n    name = field_for(\n        Challenges,\n        \"name\",\n        validate=[\n            validate.Length(\n                min=0,\n                max=80,\n                error=\"Challenge could not be saved. Challenge name too long\",\n            )\n        ],\n    )\n\n    category = field_for(\n        Challenges,\n        \"category\",\n        validate=[\n            validate.Length(\n                min=0,\n                max=80,\n                error=\"Challenge could not be saved. Challenge category too long\",\n            )\n        ],\n    )\n\n    description = field_for(\n        Challenges,\n        \"description\",\n        allow_none=True,\n        validate=[\n            validate.Length(\n                min=0,\n                max=65535,\n                error=\"Challenge could not be saved. Challenge description too long\",\n            )\n        ],\n    )\n", "path": "CTFd/schemas/challenges.py"}], "after_files": [{"content": "from marshmallow import validate\nfrom marshmallow.exceptions import ValidationError\nfrom marshmallow_sqlalchemy import field_for\n\nfrom CTFd.models import Challenges, ma\n\n\nclass ChallengeRequirementsValidator(validate.Validator):\n    default_message = \"Error parsing challenge requirements\"\n\n    def __init__(self, error=None):\n        self.error = error or self.default_message\n\n    def __call__(self, value):\n        if isinstance(value, dict) is False:\n            raise ValidationError(self.default_message)\n\n        prereqs = value.get(\"prerequisites\", [])\n        if all(prereqs) is False:\n            raise ValidationError(\n                \"Challenge requirements cannot have a null prerequisite\"\n            )\n\n        return value\n\n\nclass ChallengeSchema(ma.ModelSchema):\n    class Meta:\n        model = Challenges\n        include_fk = True\n        dump_only = (\"id\",)\n\n    name = field_for(\n        Challenges,\n        \"name\",\n        validate=[\n            validate.Length(\n                min=0,\n                max=80,\n                error=\"Challenge could not be saved. Challenge name too long\",\n            )\n        ],\n    )\n\n    category = field_for(\n        Challenges,\n        \"category\",\n        validate=[\n            validate.Length(\n                min=0,\n                max=80,\n                error=\"Challenge could not be saved. Challenge category too long\",\n            )\n        ],\n    )\n\n    description = field_for(\n        Challenges,\n        \"description\",\n        allow_none=True,\n        validate=[\n            validate.Length(\n                min=0,\n                max=65535,\n                error=\"Challenge could not be saved. Challenge description too long\",\n            )\n        ],\n    )\n\n    requirements = field_for(\n        Challenges, \"requirements\", validate=[ChallengeRequirementsValidator()],\n    )\n", "path": "CTFd/schemas/challenges.py"}]}