Skip to content

Commit 7d38a4f

Browse files
committed
Add unique_together constraint for AdvisoryToDo
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 739de9d commit 7d38a4f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

vulnerabilities/migrations/0088_advisorytodo.py renamed to vulnerabilities/migrations/0089_advisorytodo.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
# Generated by Django 4.2.17 on 2025-01-16 10:47
1+
# Generated by Django 4.2.17 on 2025-01-27 18:04
22

33
from django.db import migrations, models
44

55

66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
("vulnerabilities", "0087_update_alpine_advisory_created_by"),
9+
("vulnerabilities", "0088_fix_alpine_purl_type"),
1010
]
1111

1212
operations = [
1313
migrations.CreateModel(
14-
name="AdvisoryTODO",
14+
name="AdvisoryToDo",
1515
fields=[
1616
(
1717
"id",
1818
models.AutoField(
1919
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
2020
),
2121
),
22+
(
23+
"related_advisories_id",
24+
models.CharField(
25+
help_text="SHA1 digest of the unique_content_id field of the applicable advisories.",
26+
max_length=40,
27+
),
28+
),
2229
(
2330
"issue_type",
2431
models.CharField(
@@ -85,5 +92,8 @@ class Migration(migrations.Migration):
8592
),
8693
),
8794
],
95+
options={
96+
"unique_together": {("related_advisories_id", "issue_type")},
97+
},
8898
),
8999
]

vulnerabilities/models.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,9 +2258,9 @@ def create_new_job(self, execute_now=False):
22582258
schedules.clear_job(self.schedule_work_id)
22592259

22602260
return schedules.schedule_execution(self, execute_now) if self.is_active else None
2261-
class AdvisoryTODO(models.Model):
2262-
"""Track the TODOs for advisory/ies that need to be addressed."""
22632261

2262+
2263+
class AdvisoryTODO(models.Model):
22642264
ISSUE_TYPE_CHOICES = [
22652265
("MISSING_AFFECTED_PACKAGE", "Advisory is missing affected package"),
22662266
("MISSING_FIXED_BY_PACKAGE", "Advisory is missing fixed-by package"),
@@ -2278,6 +2278,20 @@ class AdvisoryTODO(models.Model):
22782278
("CONFLICTING_SEVERITY_SCORES", "Advisories have conflicting severity scores"),
22792279
]
22802280

2281+
2282+
class AdvisoryToDo(models.Model):
2283+
"""Track the TODOs for advisory/ies that need to be addressed."""
2284+
2285+
# Since we can not make advisories field (M2M field) unique
2286+
# (see https://code.djangoproject.com/ticket/702), we use related_advisories_id
2287+
# to avoid creating duplicate issue for same set of advisories,
2288+
related_advisories_id = models.CharField(
2289+
max_length=40,
2290+
blank=False,
2291+
null=False,
2292+
help_text="SHA1 digest of the unique_content_id field of the applicable advisories.",
2293+
)
2294+
22812295
issue_type = models.CharField(
22822296
max_length=50,
22832297
choices=ISSUE_TYPE_CHOICES,
@@ -2286,9 +2300,11 @@ class AdvisoryTODO(models.Model):
22862300
db_index=True,
22872301
help_text="Select the issue that needs to be addressed from the available options.",
22882302
)
2303+
22892304
issue_detail = models.TextField(
22902305
help_text="Additional details about the issue.",
22912306
)
2307+
22922308
advisories = models.ManyToManyField(
22932309
Advisory,
22942310
related_name="advisory_todos",
@@ -2313,3 +2329,6 @@ class AdvisoryTODO(models.Model):
23132329
resolution_detail = models.TextField(
23142330
help_text="Additional detail on how this TODO was resolved.",
23152331
)
2332+
2333+
class Meta:
2334+
unique_together = ("related_advisories_id", "issue_type")

0 commit comments

Comments
 (0)