We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Migrate DocHistory objects for RFCs
### Describe the issue

`DocHistory` objects that pertain to the RFC rather than the I-D need to be migrated to hang off the new `type_id="rfc"` `Document`. The `name` and `rfc_number` fields should be updated to match.

### Code of Conduct

- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ietf/doc/migrations/0017_move_dochistory.py`
Content:
```
1 # Generated by Django 4.2.5 on 2023-09-11 17:52
2 
3 from django.db import migrations
4 
5 from django.db.models import Subquery, OuterRef, F
6 
7 
8 def forward(apps, schema_editor):
9     DocHistory = apps.get_model("doc", "DocHistory")
10     RelatedDocument = apps.get_model("doc", "RelatedDocument")
11     DocHistory.objects.filter(type_id="draft", doc__type_id="rfc").update(type_id="rfc")
12     DocHistory.objects.filter(
13         type_id="draft", doc__type_id="draft", name__startswith="rfc"
14     ).annotate(
15         rfc_id=Subquery(
16             RelatedDocument.objects.filter(
17                 source_id=OuterRef("doc_id"), relationship_id="became_rfc"
18             ).values_list("target_id", flat=True)[:1]
19         )
20     ).update(
21         doc_id=F("rfc_id"), type_id="rfc"
22     )
23     assert not DocHistory.objects.filter(
24         name__startswith="rfc", type_id="draft"
25     ).exists()
26 
27 
28 class Migration(migrations.Migration):
29     dependencies = [
30         ("doc", "0016_delete_docalias"),
31     ]
32 
33     # There is no going back
34     operations = [migrations.RunPython(forward)]
35
```
--- 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/ietf/doc/migrations/0017_move_dochistory.py b/ietf/doc/migrations/0017_move_dochistory.py
--- a/ietf/doc/migrations/0017_move_dochistory.py
+++ b/ietf/doc/migrations/0017_move_dochistory.py
@@ -8,6 +8,7 @@
 def forward(apps, schema_editor):
     DocHistory = apps.get_model("doc", "DocHistory")
     RelatedDocument = apps.get_model("doc", "RelatedDocument")
+    Document = apps.get_model("doc", "Document")
     DocHistory.objects.filter(type_id="draft", doc__type_id="rfc").update(type_id="rfc")
     DocHistory.objects.filter(
         type_id="draft", doc__type_id="draft", name__startswith="rfc"
@@ -20,9 +21,19 @@
     ).update(
         doc_id=F("rfc_id"), type_id="rfc"
     )
+    DocHistory.objects.filter(type_id="rfc").annotate(
+        rfcno=Subquery(
+            Document.objects.filter(pk=OuterRef("doc_id")).values_list(
+                "rfc_number", flat=True
+            )[:1]
+        )
+    ).update(rfc_number=F("rfcno"))
     assert not DocHistory.objects.filter(
         name__startswith="rfc", type_id="draft"
     ).exists()
+    assert not DocHistory.objects.filter(
+        type_id="rfc", rfc_number__isnull=True
+    ).exists()
 
 
 class Migration(migrations.Migration):

{"golden_diff": "diff --git a/ietf/doc/migrations/0017_move_dochistory.py b/ietf/doc/migrations/0017_move_dochistory.py\n--- a/ietf/doc/migrations/0017_move_dochistory.py\n+++ b/ietf/doc/migrations/0017_move_dochistory.py\n@@ -8,6 +8,7 @@\n def forward(apps, schema_editor):\n     DocHistory = apps.get_model(\"doc\", \"DocHistory\")\n     RelatedDocument = apps.get_model(\"doc\", \"RelatedDocument\")\n+    Document = apps.get_model(\"doc\", \"Document\")\n     DocHistory.objects.filter(type_id=\"draft\", doc__type_id=\"rfc\").update(type_id=\"rfc\")\n     DocHistory.objects.filter(\n         type_id=\"draft\", doc__type_id=\"draft\", name__startswith=\"rfc\"\n@@ -20,9 +21,19 @@\n     ).update(\n         doc_id=F(\"rfc_id\"), type_id=\"rfc\"\n     )\n+    DocHistory.objects.filter(type_id=\"rfc\").annotate(\n+        rfcno=Subquery(\n+            Document.objects.filter(pk=OuterRef(\"doc_id\")).values_list(\n+                \"rfc_number\", flat=True\n+            )[:1]\n+        )\n+    ).update(rfc_number=F(\"rfcno\"))\n     assert not DocHistory.objects.filter(\n         name__startswith=\"rfc\", type_id=\"draft\"\n     ).exists()\n+    assert not DocHistory.objects.filter(\n+        type_id=\"rfc\", rfc_number__isnull=True\n+    ).exists()\n \n \n class Migration(migrations.Migration):\n", "issue": "Migrate DocHistory objects for RFCs\n### Describe the issue\n\n`DocHistory` objects that pertain to the RFC rather than the I-D need to be migrated to hang off the new `type_id=\"rfc\"` `Document`. The `name` and `rfc_number` fields should be updated to match.\n\n### Code of Conduct\n\n- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)\n", "before_files": [{"content": "# Generated by Django 4.2.5 on 2023-09-11 17:52\n\nfrom django.db import migrations\n\nfrom django.db.models import Subquery, OuterRef, F\n\n\ndef forward(apps, schema_editor):\n    DocHistory = apps.get_model(\"doc\", \"DocHistory\")\n    RelatedDocument = apps.get_model(\"doc\", \"RelatedDocument\")\n    DocHistory.objects.filter(type_id=\"draft\", doc__type_id=\"rfc\").update(type_id=\"rfc\")\n    DocHistory.objects.filter(\n        type_id=\"draft\", doc__type_id=\"draft\", name__startswith=\"rfc\"\n    ).annotate(\n        rfc_id=Subquery(\n            RelatedDocument.objects.filter(\n                source_id=OuterRef(\"doc_id\"), relationship_id=\"became_rfc\"\n            ).values_list(\"target_id\", flat=True)[:1]\n        )\n    ).update(\n        doc_id=F(\"rfc_id\"), type_id=\"rfc\"\n    )\n    assert not DocHistory.objects.filter(\n        name__startswith=\"rfc\", type_id=\"draft\"\n    ).exists()\n\n\nclass Migration(migrations.Migration):\n    dependencies = [\n        (\"doc\", \"0016_delete_docalias\"),\n    ]\n\n    # There is no going back\n    operations = [migrations.RunPython(forward)]\n", "path": "ietf/doc/migrations/0017_move_dochistory.py"}], "after_files": [{"content": "# Generated by Django 4.2.5 on 2023-09-11 17:52\n\nfrom django.db import migrations\n\nfrom django.db.models import Subquery, OuterRef, F\n\n\ndef forward(apps, schema_editor):\n    DocHistory = apps.get_model(\"doc\", \"DocHistory\")\n    RelatedDocument = apps.get_model(\"doc\", \"RelatedDocument\")\n    Document = apps.get_model(\"doc\", \"Document\")\n    DocHistory.objects.filter(type_id=\"draft\", doc__type_id=\"rfc\").update(type_id=\"rfc\")\n    DocHistory.objects.filter(\n        type_id=\"draft\", doc__type_id=\"draft\", name__startswith=\"rfc\"\n    ).annotate(\n        rfc_id=Subquery(\n            RelatedDocument.objects.filter(\n                source_id=OuterRef(\"doc_id\"), relationship_id=\"became_rfc\"\n            ).values_list(\"target_id\", flat=True)[:1]\n        )\n    ).update(\n        doc_id=F(\"rfc_id\"), type_id=\"rfc\"\n    )\n    DocHistory.objects.filter(type_id=\"rfc\").annotate(\n        rfcno=Subquery(\n            Document.objects.filter(pk=OuterRef(\"doc_id\")).values_list(\n                \"rfc_number\", flat=True\n            )[:1]\n        )\n    ).update(rfc_number=F(\"rfcno\"))\n    assert not DocHistory.objects.filter(\n        name__startswith=\"rfc\", type_id=\"draft\"\n    ).exists()\n    assert not DocHistory.objects.filter(\n        type_id=\"rfc\", rfc_number__isnull=True\n    ).exists()\n\n\nclass Migration(migrations.Migration):\n    dependencies = [\n        (\"doc\", \"0016_delete_docalias\"),\n    ]\n\n    # There is no going back\n    operations = [migrations.RunPython(forward)]\n", "path": "ietf/doc/migrations/0017_move_dochistory.py"}]}