Merge ~cjwatson/launchpad:stormify-bugaffectsperson into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 3ab0456a13304a7c8caf4cd7093a76f501b0f4fc
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:stormify-bugaffectsperson
Merge into: launchpad:master
Diff against target: 110 lines (+26/-11)
4 files modified
lib/lp/bugs/model/bug.py (+20/-7)
lib/lp/bugs/model/bugtasksearch.py (+1/-1)
lib/lp/hardwaredb/model/hwdb.py (+2/-2)
lib/lp/services/database/tests/test_bulk.py (+3/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+389459@code.launchpad.net

Commit message

Convert BugAffectsPerson to Storm

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/model/bug.py b/lib/lp/bugs/model/bug.py
2index 9e0f03b..e352e4b 100644
3--- a/lib/lp/bugs/model/bug.py
4+++ b/lib/lp/bugs/model/bug.py
5@@ -34,7 +34,6 @@ from six.moves.collections_abc import (
6 Set,
7 )
8 from sqlobject import (
9- BoolCol,
10 ForeignKey,
11 IntCol,
12 SQLMultipleJoin,
13@@ -60,6 +59,7 @@ from storm.expr import (
14 )
15 from storm.info import ClassAlias
16 from storm.locals import (
17+ Bool,
18 DateTime,
19 Int,
20 Reference,
21@@ -1935,7 +1935,7 @@ class Bug(SQLBase, InformationTypeMixin):
22 if dupe_bug_ids:
23 Store.of(self).find(
24 BugAffectsPerson, BugAffectsPerson.person == user,
25- BugAffectsPerson.bugID.is_in(dupe_bug_ids),
26+ BugAffectsPerson.bug_id.is_in(dupe_bug_ids),
27 ).set(affected=affected)
28 for dupe in self.duplicates:
29 dupe._flushAndInvalidate()
30@@ -2826,12 +2826,25 @@ class BugSet:
31 Bug.heat_last_updated)
32
33
34-class BugAffectsPerson(SQLBase):
35+class BugAffectsPerson(StormBase):
36 """A bug is marked as affecting a user."""
37- bug = ForeignKey(dbName='bug', foreignKey='Bug', notNull=True)
38- person = ForeignKey(dbName='person', foreignKey='Person', notNull=True)
39- affected = BoolCol(notNull=True, default=True)
40- __storm_primary__ = "bugID", "personID"
41+
42+ __storm_table__ = 'BugAffectsPerson'
43+ __storm_primary__ = 'bug_id', 'person_id'
44+
45+ bug_id = Int(name='bug', allow_none=False)
46+ bug = Reference(bug_id, 'Bug.id')
47+
48+ person_id = Int(name='person', allow_none=False)
49+ person = Reference(person_id, 'Person.id')
50+
51+ affected = Bool(allow_none=False, default=True)
52+
53+ def __init__(self, bug, person, affected=True):
54+ super(BugAffectsPerson, self).__init__()
55+ self.bug = bug
56+ self.person = person
57+ self.affected = affected
58
59
60 @implementer(IFileBugData)
61diff --git a/lib/lp/bugs/model/bugtasksearch.py b/lib/lp/bugs/model/bugtasksearch.py
62index 832dada..3335442 100644
63--- a/lib/lp/bugs/model/bugtasksearch.py
64+++ b/lib/lp/bugs/model/bugtasksearch.py
65@@ -661,7 +661,7 @@ def _build_query(params):
66 join_tables.append(
67 (BugAffectsPerson, Join(
68 BugAffectsPerson, And(
69- BugTaskFlat.bug_id == BugAffectsPerson.bugID,
70+ BugTaskFlat.bug_id == BugAffectsPerson.bug_id,
71 BugAffectsPerson.affected,
72 BugAffectsPerson.person == params.affected_user))))
73
74diff --git a/lib/lp/hardwaredb/model/hwdb.py b/lib/lp/hardwaredb/model/hwdb.py
75index 4e73474..b61b3e6 100644
76--- a/lib/lp/hardwaredb/model/hwdb.py
77+++ b/lib/lp/hardwaredb/model/hwdb.py
78@@ -481,7 +481,7 @@ class HWSubmissionSet:
79
80 if affected_by_bug:
81 affected_clauses = [
82- BugAffectsPerson.personID == HWSubmission.ownerID,
83+ BugAffectsPerson.person_id == HWSubmission.ownerID,
84 BugAffectsPerson.bug == Bug.id,
85 BugAffectsPerson.affected,
86 ]
87@@ -538,7 +538,7 @@ class HWSubmissionSet:
88 tables.append(BugSubscription)
89 if affected_by_bug:
90 person_clauses.append(
91- And(BugAffectsPerson.personID == HWSubmission.ownerID,
92+ And(BugAffectsPerson.person_id == HWSubmission.ownerID,
93 BugAffectsPerson.bug == Bug.id,
94 BugAffectsPerson.affected))
95 tables.append(BugAffectsPerson)
96diff --git a/lib/lp/services/database/tests/test_bulk.py b/lib/lp/services/database/tests/test_bulk.py
97index d1efe56..76b0471 100644
98--- a/lib/lp/services/database/tests/test_bulk.py
99+++ b/lib/lp/services/database/tests/test_bulk.py
100@@ -156,7 +156,9 @@ class TestLoaders(TestCaseWithFactory):
101
102 def test_gen_reload_queries_with_compound_primary_keys(self):
103 # gen_reload_queries() does not like compound primary keys.
104- db_queries = bulk.gen_reload_queries([BugAffectsPerson()])
105+ bap = BugAffectsPerson(
106+ bug=self.factory.makeBug(), person=self.factory.makePerson())
107+ db_queries = bulk.gen_reload_queries([bap])
108 self.assertRaisesWithContent(
109 AssertionError,
110 'Compound primary keys are not supported: BugAffectsPerson.',

Subscribers

People subscribed via source and target branches

to status/vote changes: