We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
dosing regime dose groups hotfix
We had a reported data corruption issue where a user edited content in a dosing regime and then after saving, we found multiple endpoint-groups with the same endpoint group id, which shouldn't be possible.

After investigation, we found it was an error in the signal which keeps dose-groups and endpoint-groups synced. If there were multiple representation of dose-groups, for example 5 dose-groups and 2 units, then hawc would create 10 endpoint-groups instead of 5. Further, it would create these even for endpoints where data is not extracted.

Here we fix this issue and write a few tests.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hawc/apps/animal/admin.py`
Content:
```
1 from django.contrib import admin
2 
3 from . import models
4 
5 
6 @admin.register(models.Experiment)
7 class ExperimentAdmin(admin.ModelAdmin):
8     list_display = (
9         "id",
10         "study",
11         "name",
12         "type",
13         "has_multiple_generations",
14         "chemical",
15         "cas",
16         "created",
17     )
18     list_filter = ("type", "has_multiple_generations", "chemical", "study__assessment")
19     search_fields = (
20         "study__short_citation",
21         "name",
22     )
23 
24 
25 @admin.register(models.AnimalGroup)
26 class AnimalGroupAdmin(admin.ModelAdmin):
27     list_display = (
28         "id",
29         "experiment",
30         "name",
31         "species",
32         "strain",
33         "sex",
34         "created",
35     )
36     list_filter = ("species", "strain", "sex", "experiment__study__assessment_id")
37     search_fields = ("name",)
38 
39 
40 @admin.register(models.DosingRegime)
41 class DosingRegimeAdmin(admin.ModelAdmin):
42     list_display = (
43         "id",
44         "dosed_animals",
45         "route_of_exposure",
46         "duration_exposure",
47         "num_dose_groups",
48         "created",
49     )
50     list_filter = (
51         "route_of_exposure",
52         "num_dose_groups",
53         "dosed_animals__experiment__study__assessment_id",
54     )
55     list_select_related = ("dosed_animals",)
56     search_fields = ("dosed_animals__name",)
57 
58 
59 @admin.register(models.Endpoint)
60 class EndpointAdmin(admin.ModelAdmin):
61     list_display = (
62         "id",
63         "assessment_id",
64         "animal_group",
65         "name",
66         "system",
67         "organ",
68         "effect",
69         "data_extracted",
70         "created",
71     )
72     list_filter = ("system", "organ", "data_extracted", "assessment_id")
73     search_fields = ("name",)
74
```

Path: `hawc/services/utils/git.py`
Content:
```
1 import subprocess
2 from datetime import datetime
3 
4 from pydantic import BaseModel
5 
6 
7 class Commit(BaseModel):
8     sha: str
9     dt: datetime
10 
11     @classmethod
12     def current(cls, cwd: str = ".") -> "Commit":
13         """Return information on the last commit at the repository path desired.
14 
15         Returns:
16             A Commit instance
17         """
18         cmd = "git log -1 --format=%H"
19         sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:12]
20         cmd = "git show -s --format=%ct"
21         dt = datetime.fromtimestamp(
22             int(subprocess.check_output(cmd.split(), cwd=cwd).decode().strip())
23         )
24         return cls(sha=sha, dt=dt)
25
```
--- 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/hawc/apps/animal/admin.py b/hawc/apps/animal/admin.py
--- a/hawc/apps/animal/admin.py
+++ b/hawc/apps/animal/admin.py
@@ -35,6 +35,13 @@
     )
     list_filter = ("species", "strain", "sex", "experiment__study__assessment_id")
     search_fields = ("name",)
+    raw_id_fields = ("experiment", "species", "strain", "dosing_regime", "siblings")
+
+
+class DoseGroupInline(admin.TabularInline):
+    model = models.DoseGroup
+    raw_id_fields = ("dose_units",)
+    extra = 0
 
 
 @admin.register(models.DosingRegime)
@@ -54,6 +61,12 @@
     )
     list_select_related = ("dosed_animals",)
     search_fields = ("dosed_animals__name",)
+    inlines = (DoseGroupInline,)
+
+
+class EndpointGroupInline(admin.TabularInline):
+    model = models.EndpointGroup
+    extra = 0
 
 
 @admin.register(models.Endpoint)
@@ -71,3 +84,13 @@
     )
     list_filter = ("system", "organ", "data_extracted", "assessment_id")
     search_fields = ("name",)
+    raw_id_fields = (
+        "assessment",
+        "animal_group",
+        "system_term",
+        "organ_term",
+        "effect_term",
+        "effect_subtype_term",
+        "name_term",
+    )
+    inlines = (EndpointGroupInline,)
diff --git a/hawc/services/utils/git.py b/hawc/services/utils/git.py
--- a/hawc/services/utils/git.py
+++ b/hawc/services/utils/git.py
@@ -16,7 +16,7 @@
             A Commit instance
         """
         cmd = "git log -1 --format=%H"
-        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:12]
+        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:8]
         cmd = "git show -s --format=%ct"
         dt = datetime.fromtimestamp(
             int(subprocess.check_output(cmd.split(), cwd=cwd).decode().strip())

{"golden_diff": "diff --git a/hawc/apps/animal/admin.py b/hawc/apps/animal/admin.py\n--- a/hawc/apps/animal/admin.py\n+++ b/hawc/apps/animal/admin.py\n@@ -35,6 +35,13 @@\n     )\n     list_filter = (\"species\", \"strain\", \"sex\", \"experiment__study__assessment_id\")\n     search_fields = (\"name\",)\n+    raw_id_fields = (\"experiment\", \"species\", \"strain\", \"dosing_regime\", \"siblings\")\n+\n+\n+class DoseGroupInline(admin.TabularInline):\n+    model = models.DoseGroup\n+    raw_id_fields = (\"dose_units\",)\n+    extra = 0\n \n \n @admin.register(models.DosingRegime)\n@@ -54,6 +61,12 @@\n     )\n     list_select_related = (\"dosed_animals\",)\n     search_fields = (\"dosed_animals__name\",)\n+    inlines = (DoseGroupInline,)\n+\n+\n+class EndpointGroupInline(admin.TabularInline):\n+    model = models.EndpointGroup\n+    extra = 0\n \n \n @admin.register(models.Endpoint)\n@@ -71,3 +84,13 @@\n     )\n     list_filter = (\"system\", \"organ\", \"data_extracted\", \"assessment_id\")\n     search_fields = (\"name\",)\n+    raw_id_fields = (\n+        \"assessment\",\n+        \"animal_group\",\n+        \"system_term\",\n+        \"organ_term\",\n+        \"effect_term\",\n+        \"effect_subtype_term\",\n+        \"name_term\",\n+    )\n+    inlines = (EndpointGroupInline,)\ndiff --git a/hawc/services/utils/git.py b/hawc/services/utils/git.py\n--- a/hawc/services/utils/git.py\n+++ b/hawc/services/utils/git.py\n@@ -16,7 +16,7 @@\n             A Commit instance\n         \"\"\"\n         cmd = \"git log -1 --format=%H\"\n-        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:12]\n+        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:8]\n         cmd = \"git show -s --format=%ct\"\n         dt = datetime.fromtimestamp(\n             int(subprocess.check_output(cmd.split(), cwd=cwd).decode().strip())\n", "issue": "dosing regime dose groups hotfix\nWe had a reported data corruption issue where a user edited content in a dosing regime and then after saving, we found multiple endpoint-groups with the same endpoint group id, which shouldn't be possible.\r\n\r\nAfter investigation, we found it was an error in the signal which keeps dose-groups and endpoint-groups synced. If there were multiple representation of dose-groups, for example 5 dose-groups and 2 units, then hawc would create 10 endpoint-groups instead of 5. Further, it would create these even for endpoints where data is not extracted.\r\n\r\nHere we fix this issue and write a few tests.\n", "before_files": [{"content": "from django.contrib import admin\n\nfrom . import models\n\n\n@admin.register(models.Experiment)\nclass ExperimentAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"study\",\n        \"name\",\n        \"type\",\n        \"has_multiple_generations\",\n        \"chemical\",\n        \"cas\",\n        \"created\",\n    )\n    list_filter = (\"type\", \"has_multiple_generations\", \"chemical\", \"study__assessment\")\n    search_fields = (\n        \"study__short_citation\",\n        \"name\",\n    )\n\n\n@admin.register(models.AnimalGroup)\nclass AnimalGroupAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"experiment\",\n        \"name\",\n        \"species\",\n        \"strain\",\n        \"sex\",\n        \"created\",\n    )\n    list_filter = (\"species\", \"strain\", \"sex\", \"experiment__study__assessment_id\")\n    search_fields = (\"name\",)\n\n\n@admin.register(models.DosingRegime)\nclass DosingRegimeAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"dosed_animals\",\n        \"route_of_exposure\",\n        \"duration_exposure\",\n        \"num_dose_groups\",\n        \"created\",\n    )\n    list_filter = (\n        \"route_of_exposure\",\n        \"num_dose_groups\",\n        \"dosed_animals__experiment__study__assessment_id\",\n    )\n    list_select_related = (\"dosed_animals\",)\n    search_fields = (\"dosed_animals__name\",)\n\n\n@admin.register(models.Endpoint)\nclass EndpointAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"assessment_id\",\n        \"animal_group\",\n        \"name\",\n        \"system\",\n        \"organ\",\n        \"effect\",\n        \"data_extracted\",\n        \"created\",\n    )\n    list_filter = (\"system\", \"organ\", \"data_extracted\", \"assessment_id\")\n    search_fields = (\"name\",)\n", "path": "hawc/apps/animal/admin.py"}, {"content": "import subprocess\nfrom datetime import datetime\n\nfrom pydantic import BaseModel\n\n\nclass Commit(BaseModel):\n    sha: str\n    dt: datetime\n\n    @classmethod\n    def current(cls, cwd: str = \".\") -> \"Commit\":\n        \"\"\"Return information on the last commit at the repository path desired.\n\n        Returns:\n            A Commit instance\n        \"\"\"\n        cmd = \"git log -1 --format=%H\"\n        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:12]\n        cmd = \"git show -s --format=%ct\"\n        dt = datetime.fromtimestamp(\n            int(subprocess.check_output(cmd.split(), cwd=cwd).decode().strip())\n        )\n        return cls(sha=sha, dt=dt)\n", "path": "hawc/services/utils/git.py"}], "after_files": [{"content": "from django.contrib import admin\n\nfrom . import models\n\n\n@admin.register(models.Experiment)\nclass ExperimentAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"study\",\n        \"name\",\n        \"type\",\n        \"has_multiple_generations\",\n        \"chemical\",\n        \"cas\",\n        \"created\",\n    )\n    list_filter = (\"type\", \"has_multiple_generations\", \"chemical\", \"study__assessment\")\n    search_fields = (\n        \"study__short_citation\",\n        \"name\",\n    )\n\n\n@admin.register(models.AnimalGroup)\nclass AnimalGroupAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"experiment\",\n        \"name\",\n        \"species\",\n        \"strain\",\n        \"sex\",\n        \"created\",\n    )\n    list_filter = (\"species\", \"strain\", \"sex\", \"experiment__study__assessment_id\")\n    search_fields = (\"name\",)\n    raw_id_fields = (\"experiment\", \"species\", \"strain\", \"dosing_regime\", \"siblings\")\n\n\nclass DoseGroupInline(admin.TabularInline):\n    model = models.DoseGroup\n    raw_id_fields = (\"dose_units\",)\n    extra = 0\n\n\n@admin.register(models.DosingRegime)\nclass DosingRegimeAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"dosed_animals\",\n        \"route_of_exposure\",\n        \"duration_exposure\",\n        \"num_dose_groups\",\n        \"created\",\n    )\n    list_filter = (\n        \"route_of_exposure\",\n        \"num_dose_groups\",\n        \"dosed_animals__experiment__study__assessment_id\",\n    )\n    list_select_related = (\"dosed_animals\",)\n    search_fields = (\"dosed_animals__name\",)\n    inlines = (DoseGroupInline,)\n\n\nclass EndpointGroupInline(admin.TabularInline):\n    model = models.EndpointGroup\n    extra = 0\n\n\n@admin.register(models.Endpoint)\nclass EndpointAdmin(admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"assessment_id\",\n        \"animal_group\",\n        \"name\",\n        \"system\",\n        \"organ\",\n        \"effect\",\n        \"data_extracted\",\n        \"created\",\n    )\n    list_filter = (\"system\", \"organ\", \"data_extracted\", \"assessment_id\")\n    search_fields = (\"name\",)\n    raw_id_fields = (\n        \"assessment\",\n        \"animal_group\",\n        \"system_term\",\n        \"organ_term\",\n        \"effect_term\",\n        \"effect_subtype_term\",\n        \"name_term\",\n    )\n    inlines = (EndpointGroupInline,)\n", "path": "hawc/apps/animal/admin.py"}, {"content": "import subprocess\nfrom datetime import datetime\n\nfrom pydantic import BaseModel\n\n\nclass Commit(BaseModel):\n    sha: str\n    dt: datetime\n\n    @classmethod\n    def current(cls, cwd: str = \".\") -> \"Commit\":\n        \"\"\"Return information on the last commit at the repository path desired.\n\n        Returns:\n            A Commit instance\n        \"\"\"\n        cmd = \"git log -1 --format=%H\"\n        sha = subprocess.check_output(cmd.split(), cwd=cwd).decode().strip()[:8]\n        cmd = \"git show -s --format=%ct\"\n        dt = datetime.fromtimestamp(\n            int(subprocess.check_output(cmd.split(), cwd=cwd).decode().strip())\n        )\n        return cls(sha=sha, dt=dt)\n", "path": "hawc/services/utils/git.py"}]}