summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Helmert III <ajak@gentoo.org>2023-12-17 21:12:20 -0800
committerJohn Helmert III <ajak@gentoo.org>2023-12-17 21:21:15 -0800
commit99988d5fd9276175f186278afa3714738fd58618 (patch)
treea43d85d3ef83196280c3f964777dd924b96c845e
parenttest_views: add a test to trigger bug table primary key error (diff)
downloadglsamaker-99988d5fd9276175f186278afa3714738fd58618.tar.gz
glsamaker-99988d5fd9276175f186278afa3714738fd58618.tar.bz2
glsamaker-99988d5fd9276175f186278afa3714738fd58618.zip
Revert "models/bug: instances are implicitly deduplicated"
This reverts commit 03ebd8805524fb7d98ab6db6b987a36e32d0a95f. This turned out to be wrong, and now triggers an exception with duplicate bug rows. Signed-off-by: John Helmert III <ajak@gentoo.org>
-rw-r--r--glsamaker/autoglsa.py2
-rw-r--r--glsamaker/models/bug.py9
-rw-r--r--glsamaker/views.py2
-rw-r--r--test/models/test_glsa.py2
4 files changed, 12 insertions, 3 deletions
diff --git a/glsamaker/autoglsa.py b/glsamaker/autoglsa.py
index fd9b984..faac903 100644
--- a/glsamaker/autoglsa.py
+++ b/glsamaker/autoglsa.py
@@ -244,7 +244,7 @@ def autogenerate_glsa(bugs: list[BugzillaBug]) -> Tuple[GLSA, list[NoAtomInSumma
packages, errors = get_max_versions(bugs)
- glsa.bugs = [Bug(str(bug.id)) for bug in bugs]
+ glsa.bugs = [Bug.new(str(bug.id)) for bug in bugs]
aliases = bugs_aliases([bug.bug_id for bug in glsa.bugs])
glsa.references = [Reference.new(alias) for alias in aliases]
diff --git a/glsamaker/models/bug.py b/glsamaker/models/bug.py
index 9fc6ff0..671290d 100644
--- a/glsamaker/models/bug.py
+++ b/glsamaker/models/bug.py
@@ -8,3 +8,12 @@ class Bug(base):
def __init__(self, bug):
self.bug_id = bug
+
+ # TODO: maybe this would be more comfortable by hacking about with
+ # __new__ so that a class method doesn't have to be called?
+ @classmethod
+ def new(cls, bug):
+ row = db.session.query(Bug).filter_by(bug_id=bug).first()
+ if row:
+ return row
+ return Bug(bug)
diff --git a/glsamaker/views.py b/glsamaker/views.py
index fd4a822..2b31bbb 100644
--- a/glsamaker/views.py
+++ b/glsamaker/views.py
@@ -200,7 +200,7 @@ def edit_glsa(glsa_id=None):
glsa.title = form.title.data.strip()
glsa.synopsis = form.synopsis.data.strip()
glsa.product_type = form.product_type.data.strip()
- glsa.bugs = [Bug(bug.strip()) for bug in form.bugs.data.split(",")]
+ glsa.bugs = [Bug.new(bug.strip()) for bug in form.bugs.data.split(",")]
glsa.access = form.access.data.strip()
glsa.affected = parse_atoms(request, "unaffected") + parse_atoms(
request, "vulnerable"
diff --git a/test/models/test_glsa.py b/test/models/test_glsa.py
index c794670..4456886 100644
--- a/test/models/test_glsa.py
+++ b/test/models/test_glsa.py
@@ -14,7 +14,7 @@ def test_get_bugs(db):
ids = ["1234", "4321", "1111", "2222"]
glsa = GLSA()
for x in ids:
- glsa.bugs.append(Bug(x))
+ glsa.bugs.append(Bug.new(x))
db.session.merge(glsa)