We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Sources should automatically have segments
From #257:

> A source should always have a segment. It is either "Cantus Database" or "Sequence Database". It's a foreign key field. In cases where a source doesn't have a segment, it is probably a test source that we created.
> Desired behaviour: when creating a source, assign it to "Cantus Database" by default.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `django/cantusdb_project/main_app/models/source.py`
Content:
```
1 from django.db import models
2 from main_app.models import BaseModel
3 from django.contrib.auth import get_user_model
4 
5 
6 class Source(BaseModel):
7     cursus_choices = [("Monastic", "Monastic"), ("Secular", "Secular")]
8     source_status_choices = [
9         (
10             "Editing process (not all the fields have been proofread)",
11             "Editing process (not all the fields have been proofread)",
12         ),
13         ("Published / Complete", "Published / Complete"),
14         ("Published / Proofread pending", "Published / Proofread pending"),
15         ("Unpublished / Editing process", "Unpublished / Editing process"),
16         ("Unpublished / Indexing process", "Unpublished / Indexing process"),
17         ("Unpublished / Proofread pending", "Unpublished / Proofread pending"),
18         ("Unpublished / Proofreading process", "Unpublished / Proofreading process"),
19     ]
20 
21     # sources with public=False cannot be accessed by its url (access denied) and do not appear in source list
22     public = models.BooleanField(blank=True, null=True)
23     # sources with visible=False can be accessed by typing in the url, but do not appear in source list
24     visible = models.BooleanField(blank=True, null=True)
25     title = models.CharField(
26         max_length=255,
27         help_text="Full Manuscript Identification (City, Archive, Shelf-mark)",
28     )
29     # the siglum field as implemented on the old Cantus is composed of both the RISM siglum and the shelfmark
30     # it is a human-readable ID for a source
31     siglum = models.CharField(
32         max_length=63, 
33         null=True, 
34         blank=True,
35         help_text="RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).",
36     )
37     # the RISM siglum uniquely identifies a library or holding institution
38     rism_siglum = models.ForeignKey(
39         "RismSiglum", on_delete=models.PROTECT, null=True, blank=True,
40     )
41     provenance = models.ForeignKey(
42         "Provenance",
43         on_delete=models.PROTECT,
44         help_text="If the origin is unknown, select a location where the source was "
45         "used later in its lifetime and provide details in the "
46         '"Provenance notes" field.',
47         null=True,
48         blank=True,
49     )
50     provenance_notes = models.TextField(
51         blank=True,
52         null=True,
53         help_text="More exact indication of the provenance (if necessary)",
54     )
55     full_source = models.BooleanField(blank=True, null=True)
56     date = models.CharField(
57         blank=True,
58         null=True,
59         max_length=63,
60         help_text='Date of the manuscript (e.g. "1200s", "1300-1350", etc.)',
61     )
62     century = models.ManyToManyField("Century", related_name="sources")
63     notation = models.ManyToManyField("Notation", related_name="sources")
64     cursus = models.CharField(
65         blank=True, null=True, choices=cursus_choices, max_length=63
66     )
67     # TODO: Fill this field up with JSON info when I have access to the Users
68     current_editors = models.ManyToManyField(get_user_model(), related_name="sources_user_can_edit")
69     inventoried_by = models.ManyToManyField(
70         "Indexer", related_name="sources_inventoried"
71     )
72     full_text_entered_by = models.ManyToManyField(
73         "Indexer", related_name="entered_full_text_for_sources"
74     )
75     melodies_entered_by = models.ManyToManyField(
76         "Indexer", related_name="entered_melody_for_sources"
77     )
78     proofreaders = models.ManyToManyField("Indexer", related_name="proofread_sources")
79     other_editors = models.ManyToManyField("Indexer", related_name="edited_sources")
80     segment = models.ForeignKey(
81         "Segment", on_delete=models.PROTECT, blank=True, null=True
82     )
83     source_status = models.CharField(blank=True, null=True, max_length=255)
84     complete_inventory = models.BooleanField(blank=True, null=True)
85     summary = models.TextField(blank=True, null=True)
86     liturgical_occasions = models.TextField(blank=True, null=True)
87     description = models.TextField(blank=True, null=True)
88     selected_bibliography = models.TextField(blank=True, null=True)
89     image_link = models.URLField(
90         blank=True, 
91         null=True,
92         help_text='HTTP link to the image gallery of the source.',
93     )
94     indexing_notes = models.TextField(blank=True, null=True)
95     indexing_date = models.TextField(blank=True, null=True)
96     json_info = models.JSONField(blank=True, null=True)
97     fragmentarium_id = models.CharField(max_length=15, blank=True, null=True)
98     dact_id = models.CharField(max_length=15, blank=True, null=True)
99 
100     def number_of_chants(self) -> int:
101         """Returns the number of Chants and Sequences in this Source."""
102         return self.chant_set.count() + self.sequence_set.count()
103 
104     def number_of_melodies(self) -> int:
105         """Returns the number of Chants in this Source that have melodies."""
106         return self.chant_set.filter(volpiano__isnull=False).count()
107 
108     def __str__(self):
109         string = '{t} ({i})'.format(t=self.title, i=self.id)
110         return string
111 
112
```
--- 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/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py
--- a/django/cantusdb_project/main_app/models/source.py
+++ b/django/cantusdb_project/main_app/models/source.py
@@ -1,5 +1,5 @@
 from django.db import models
-from main_app.models import BaseModel
+from main_app.models import BaseModel, Segment
 from django.contrib.auth import get_user_model
 
 
@@ -109,4 +109,8 @@
         string = '{t} ({i})'.format(t=self.title, i=self.id)
         return string
 
-    
\ No newline at end of file
+    def save(self, *args, **kwargs):
+        # when creating a source, assign it to "Cantus Database" by default
+        cantus_db_segment = Segment.objects.get(name="CANTUS Database")
+        self.segment = cantus_db_segment
+        super().save(*args, **kwargs)

{"golden_diff": "diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py\n--- a/django/cantusdb_project/main_app/models/source.py\n+++ b/django/cantusdb_project/main_app/models/source.py\n@@ -1,5 +1,5 @@\n from django.db import models\n-from main_app.models import BaseModel\n+from main_app.models import BaseModel, Segment\n from django.contrib.auth import get_user_model\n \n \n@@ -109,4 +109,8 @@\n         string = '{t} ({i})'.format(t=self.title, i=self.id)\n         return string\n \n-    \n\\ No newline at end of file\n+    def save(self, *args, **kwargs):\n+        # when creating a source, assign it to \"Cantus Database\" by default\n+        cantus_db_segment = Segment.objects.get(name=\"CANTUS Database\")\n+        self.segment = cantus_db_segment\n+        super().save(*args, **kwargs)\n", "issue": "Sources should automatically have segments\nFrom #257:\r\n\r\n> A source should always have a segment. It is either \"Cantus Database\" or \"Sequence Database\". It's a foreign key field. In cases where a source doesn't have a segment, it is probably a test source that we created.\r\n> Desired behaviour: when creating a source, assign it to \"Cantus Database\" by default.\n", "before_files": [{"content": "from django.db import models\nfrom main_app.models import BaseModel\nfrom django.contrib.auth import get_user_model\n\n\nclass Source(BaseModel):\n    cursus_choices = [(\"Monastic\", \"Monastic\"), (\"Secular\", \"Secular\")]\n    source_status_choices = [\n        (\n            \"Editing process (not all the fields have been proofread)\",\n            \"Editing process (not all the fields have been proofread)\",\n        ),\n        (\"Published / Complete\", \"Published / Complete\"),\n        (\"Published / Proofread pending\", \"Published / Proofread pending\"),\n        (\"Unpublished / Editing process\", \"Unpublished / Editing process\"),\n        (\"Unpublished / Indexing process\", \"Unpublished / Indexing process\"),\n        (\"Unpublished / Proofread pending\", \"Unpublished / Proofread pending\"),\n        (\"Unpublished / Proofreading process\", \"Unpublished / Proofreading process\"),\n    ]\n\n    # sources with public=False cannot be accessed by its url (access denied) and do not appear in source list\n    public = models.BooleanField(blank=True, null=True)\n    # sources with visible=False can be accessed by typing in the url, but do not appear in source list\n    visible = models.BooleanField(blank=True, null=True)\n    title = models.CharField(\n        max_length=255,\n        help_text=\"Full Manuscript Identification (City, Archive, Shelf-mark)\",\n    )\n    # the siglum field as implemented on the old Cantus is composed of both the RISM siglum and the shelfmark\n    # it is a human-readable ID for a source\n    siglum = models.CharField(\n        max_length=63, \n        null=True, \n        blank=True,\n        help_text=\"RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).\",\n    )\n    # the RISM siglum uniquely identifies a library or holding institution\n    rism_siglum = models.ForeignKey(\n        \"RismSiglum\", on_delete=models.PROTECT, null=True, blank=True,\n    )\n    provenance = models.ForeignKey(\n        \"Provenance\",\n        on_delete=models.PROTECT,\n        help_text=\"If the origin is unknown, select a location where the source was \"\n        \"used later in its lifetime and provide details in the \"\n        '\"Provenance notes\" field.',\n        null=True,\n        blank=True,\n    )\n    provenance_notes = models.TextField(\n        blank=True,\n        null=True,\n        help_text=\"More exact indication of the provenance (if necessary)\",\n    )\n    full_source = models.BooleanField(blank=True, null=True)\n    date = models.CharField(\n        blank=True,\n        null=True,\n        max_length=63,\n        help_text='Date of the manuscript (e.g. \"1200s\", \"1300-1350\", etc.)',\n    )\n    century = models.ManyToManyField(\"Century\", related_name=\"sources\")\n    notation = models.ManyToManyField(\"Notation\", related_name=\"sources\")\n    cursus = models.CharField(\n        blank=True, null=True, choices=cursus_choices, max_length=63\n    )\n    # TODO: Fill this field up with JSON info when I have access to the Users\n    current_editors = models.ManyToManyField(get_user_model(), related_name=\"sources_user_can_edit\")\n    inventoried_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"sources_inventoried\"\n    )\n    full_text_entered_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"entered_full_text_for_sources\"\n    )\n    melodies_entered_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"entered_melody_for_sources\"\n    )\n    proofreaders = models.ManyToManyField(\"Indexer\", related_name=\"proofread_sources\")\n    other_editors = models.ManyToManyField(\"Indexer\", related_name=\"edited_sources\")\n    segment = models.ForeignKey(\n        \"Segment\", on_delete=models.PROTECT, blank=True, null=True\n    )\n    source_status = models.CharField(blank=True, null=True, max_length=255)\n    complete_inventory = models.BooleanField(blank=True, null=True)\n    summary = models.TextField(blank=True, null=True)\n    liturgical_occasions = models.TextField(blank=True, null=True)\n    description = models.TextField(blank=True, null=True)\n    selected_bibliography = models.TextField(blank=True, null=True)\n    image_link = models.URLField(\n        blank=True, \n        null=True,\n        help_text='HTTP link to the image gallery of the source.',\n    )\n    indexing_notes = models.TextField(blank=True, null=True)\n    indexing_date = models.TextField(blank=True, null=True)\n    json_info = models.JSONField(blank=True, null=True)\n    fragmentarium_id = models.CharField(max_length=15, blank=True, null=True)\n    dact_id = models.CharField(max_length=15, blank=True, null=True)\n\n    def number_of_chants(self) -> int:\n        \"\"\"Returns the number of Chants and Sequences in this Source.\"\"\"\n        return self.chant_set.count() + self.sequence_set.count()\n\n    def number_of_melodies(self) -> int:\n        \"\"\"Returns the number of Chants in this Source that have melodies.\"\"\"\n        return self.chant_set.filter(volpiano__isnull=False).count()\n\n    def __str__(self):\n        string = '{t} ({i})'.format(t=self.title, i=self.id)\n        return string\n\n    ", "path": "django/cantusdb_project/main_app/models/source.py"}], "after_files": [{"content": "from django.db import models\nfrom main_app.models import BaseModel, Segment\nfrom django.contrib.auth import get_user_model\n\n\nclass Source(BaseModel):\n    cursus_choices = [(\"Monastic\", \"Monastic\"), (\"Secular\", \"Secular\")]\n    source_status_choices = [\n        (\n            \"Editing process (not all the fields have been proofread)\",\n            \"Editing process (not all the fields have been proofread)\",\n        ),\n        (\"Published / Complete\", \"Published / Complete\"),\n        (\"Published / Proofread pending\", \"Published / Proofread pending\"),\n        (\"Unpublished / Editing process\", \"Unpublished / Editing process\"),\n        (\"Unpublished / Indexing process\", \"Unpublished / Indexing process\"),\n        (\"Unpublished / Proofread pending\", \"Unpublished / Proofread pending\"),\n        (\"Unpublished / Proofreading process\", \"Unpublished / Proofreading process\"),\n    ]\n\n    # sources with public=False cannot be accessed by its url (access denied) and do not appear in source list\n    public = models.BooleanField(blank=True, null=True)\n    # sources with visible=False can be accessed by typing in the url, but do not appear in source list\n    visible = models.BooleanField(blank=True, null=True)\n    title = models.CharField(\n        max_length=255,\n        help_text=\"Full Manuscript Identification (City, Archive, Shelf-mark)\",\n    )\n    # the siglum field as implemented on the old Cantus is composed of both the RISM siglum and the shelfmark\n    # it is a human-readable ID for a source\n    siglum = models.CharField(\n        max_length=63, \n        null=True, \n        blank=True,\n        help_text=\"RISM-style siglum + Shelf-mark (e.g. GB-Ob 202).\",\n    )\n    # the RISM siglum uniquely identifies a library or holding institution\n    rism_siglum = models.ForeignKey(\n        \"RismSiglum\", on_delete=models.PROTECT, null=True, blank=True,\n    )\n    provenance = models.ForeignKey(\n        \"Provenance\",\n        on_delete=models.PROTECT,\n        help_text=\"If the origin is unknown, select a location where the source was \"\n        \"used later in its lifetime and provide details in the \"\n        '\"Provenance notes\" field.',\n        null=True,\n        blank=True,\n    )\n    provenance_notes = models.TextField(\n        blank=True,\n        null=True,\n        help_text=\"More exact indication of the provenance (if necessary)\",\n    )\n    full_source = models.BooleanField(blank=True, null=True)\n    date = models.CharField(\n        blank=True,\n        null=True,\n        max_length=63,\n        help_text='Date of the manuscript (e.g. \"1200s\", \"1300-1350\", etc.)',\n    )\n    century = models.ManyToManyField(\"Century\", related_name=\"sources\")\n    notation = models.ManyToManyField(\"Notation\", related_name=\"sources\")\n    cursus = models.CharField(\n        blank=True, null=True, choices=cursus_choices, max_length=63\n    )\n    # TODO: Fill this field up with JSON info when I have access to the Users\n    current_editors = models.ManyToManyField(get_user_model(), related_name=\"sources_user_can_edit\")\n    inventoried_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"sources_inventoried\"\n    )\n    full_text_entered_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"entered_full_text_for_sources\"\n    )\n    melodies_entered_by = models.ManyToManyField(\n        \"Indexer\", related_name=\"entered_melody_for_sources\"\n    )\n    proofreaders = models.ManyToManyField(\"Indexer\", related_name=\"proofread_sources\")\n    other_editors = models.ManyToManyField(\"Indexer\", related_name=\"edited_sources\")\n    segment = models.ForeignKey(\n        \"Segment\", on_delete=models.PROTECT, blank=True, null=True\n    )\n    source_status = models.CharField(blank=True, null=True, max_length=255)\n    complete_inventory = models.BooleanField(blank=True, null=True)\n    summary = models.TextField(blank=True, null=True)\n    liturgical_occasions = models.TextField(blank=True, null=True)\n    description = models.TextField(blank=True, null=True)\n    selected_bibliography = models.TextField(blank=True, null=True)\n    image_link = models.URLField(\n        blank=True, \n        null=True,\n        help_text='HTTP link to the image gallery of the source.',\n    )\n    indexing_notes = models.TextField(blank=True, null=True)\n    indexing_date = models.TextField(blank=True, null=True)\n    json_info = models.JSONField(blank=True, null=True)\n    fragmentarium_id = models.CharField(max_length=15, blank=True, null=True)\n    dact_id = models.CharField(max_length=15, blank=True, null=True)\n\n    def number_of_chants(self) -> int:\n        \"\"\"Returns the number of Chants and Sequences in this Source.\"\"\"\n        return self.chant_set.count() + self.sequence_set.count()\n\n    def number_of_melodies(self) -> int:\n        \"\"\"Returns the number of Chants in this Source that have melodies.\"\"\"\n        return self.chant_set.filter(volpiano__isnull=False).count()\n\n    def __str__(self):\n        string = '{t} ({i})'.format(t=self.title, i=self.id)\n        return string\n\n    def save(self, *args, **kwargs):\n        # when creating a source, assign it to \"Cantus Database\" by default\n        cantus_db_segment = Segment.objects.get(name=\"CANTUS Database\")\n        self.segment = cantus_db_segment\n        super().save(*args, **kwargs)\n", "path": "django/cantusdb_project/main_app/models/source.py"}]}