launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25185
[Merge] ~cjwatson/launchpad:stormify-bugaffectsperson into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-bugaffectsperson into launchpad:master.
Commit message:
Convert BugAffectsPerson to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/389459
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-bugaffectsperson into launchpad:master.
diff --git a/lib/lp/bugs/model/bug.py b/lib/lp/bugs/model/bug.py
index 3000056..fb12a99 100644
--- a/lib/lp/bugs/model/bug.py
+++ b/lib/lp/bugs/model/bug.py
@@ -34,7 +34,6 @@ from six.moves.collections_abc import (
Set,
)
from sqlobject import (
- BoolCol,
ForeignKey,
IntCol,
SQLMultipleJoin,
@@ -60,6 +59,7 @@ from storm.expr import (
)
from storm.info import ClassAlias
from storm.locals import (
+ Bool,
DateTime,
Int,
Reference,
@@ -1936,7 +1936,7 @@ class Bug(SQLBase, InformationTypeMixin):
if dupe_bug_ids:
Store.of(self).find(
BugAffectsPerson, BugAffectsPerson.person == user,
- BugAffectsPerson.bugID.is_in(dupe_bug_ids),
+ BugAffectsPerson.bug_id.is_in(dupe_bug_ids),
).set(affected=affected)
for dupe in self.duplicates:
dupe._flushAndInvalidate()
@@ -2839,12 +2839,25 @@ class BugSet:
Bug.heat_last_updated)
-class BugAffectsPerson(SQLBase):
+class BugAffectsPerson(StormBase):
"""A bug is marked as affecting a user."""
- bug = ForeignKey(dbName='bug', foreignKey='Bug', notNull=True)
- person = ForeignKey(dbName='person', foreignKey='Person', notNull=True)
- affected = BoolCol(notNull=True, default=True)
- __storm_primary__ = "bugID", "personID"
+
+ __storm_table__ = 'BugAffectsPerson'
+ __storm_primary__ = 'bug_id', 'person_id'
+
+ bug_id = Int(name='bug', allow_none=False)
+ bug = Reference(bug_id, 'Bug.id')
+
+ person_id = Int(name='person', allow_none=False)
+ person = Reference(person_id, 'Person.id')
+
+ affected = Bool(allow_none=False, default=True)
+
+ def __init__(self, bug, person, affected=True):
+ super(BugAffectsPerson, self).__init__()
+ self.bug = bug
+ self.person = person
+ self.affected = affected
@implementer(IFileBugData)
diff --git a/lib/lp/bugs/model/bugtasksearch.py b/lib/lp/bugs/model/bugtasksearch.py
index 334cd6a..64f912c 100644
--- a/lib/lp/bugs/model/bugtasksearch.py
+++ b/lib/lp/bugs/model/bugtasksearch.py
@@ -661,7 +661,7 @@ def _build_query(params):
join_tables.append(
(BugAffectsPerson, Join(
BugAffectsPerson, And(
- BugTaskFlat.bug_id == BugAffectsPerson.bugID,
+ BugTaskFlat.bug_id == BugAffectsPerson.bug_id,
BugAffectsPerson.affected,
BugAffectsPerson.person == params.affected_user))))
@@ -1048,7 +1048,7 @@ def _build_hardware_related_clause(params):
HWSubmission.ownerID == Bug.ownerID)
if params.hardware_owner_is_affected_by_bug:
bug_link_clauses.append(
- And(BugAffectsPerson.personID == HWSubmission.ownerID,
+ And(BugAffectsPerson.person_id == HWSubmission.ownerID,
BugAffectsPerson.bug == Bug.id,
BugAffectsPerson.affected))
tables.append(BugAffectsPerson)
diff --git a/lib/lp/hardwaredb/model/hwdb.py b/lib/lp/hardwaredb/model/hwdb.py
index 4e73474..b61b3e6 100644
--- a/lib/lp/hardwaredb/model/hwdb.py
+++ b/lib/lp/hardwaredb/model/hwdb.py
@@ -481,7 +481,7 @@ class HWSubmissionSet:
if affected_by_bug:
affected_clauses = [
- BugAffectsPerson.personID == HWSubmission.ownerID,
+ BugAffectsPerson.person_id == HWSubmission.ownerID,
BugAffectsPerson.bug == Bug.id,
BugAffectsPerson.affected,
]
@@ -538,7 +538,7 @@ class HWSubmissionSet:
tables.append(BugSubscription)
if affected_by_bug:
person_clauses.append(
- And(BugAffectsPerson.personID == HWSubmission.ownerID,
+ And(BugAffectsPerson.person_id == HWSubmission.ownerID,
BugAffectsPerson.bug == Bug.id,
BugAffectsPerson.affected))
tables.append(BugAffectsPerson)
diff --git a/lib/lp/services/database/tests/test_bulk.py b/lib/lp/services/database/tests/test_bulk.py
index d1efe56..76b0471 100644
--- a/lib/lp/services/database/tests/test_bulk.py
+++ b/lib/lp/services/database/tests/test_bulk.py
@@ -156,7 +156,9 @@ class TestLoaders(TestCaseWithFactory):
def test_gen_reload_queries_with_compound_primary_keys(self):
# gen_reload_queries() does not like compound primary keys.
- db_queries = bulk.gen_reload_queries([BugAffectsPerson()])
+ bap = BugAffectsPerson(
+ bug=self.factory.makeBug(), person=self.factory.makePerson())
+ db_queries = bulk.gen_reload_queries([bap])
self.assertRaisesWithContent(
AssertionError,
'Compound primary keys are not supported: BugAffectsPerson.',