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
diff --git a/lib/lp/bugs/model/bug.py b/lib/lp/bugs/model/bug.py
index 9e0f03b..e352e4b 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 (
34 Set,34 Set,
35 )35 )
36from sqlobject import (36from sqlobject import (
37 BoolCol,
38 ForeignKey,37 ForeignKey,
39 IntCol,38 IntCol,
40 SQLMultipleJoin,39 SQLMultipleJoin,
@@ -60,6 +59,7 @@ from storm.expr import (
60 )59 )
61from storm.info import ClassAlias60from storm.info import ClassAlias
62from storm.locals import (61from storm.locals import (
62 Bool,
63 DateTime,63 DateTime,
64 Int,64 Int,
65 Reference,65 Reference,
@@ -1935,7 +1935,7 @@ class Bug(SQLBase, InformationTypeMixin):
1935 if dupe_bug_ids:1935 if dupe_bug_ids:
1936 Store.of(self).find(1936 Store.of(self).find(
1937 BugAffectsPerson, BugAffectsPerson.person == user,1937 BugAffectsPerson, BugAffectsPerson.person == user,
1938 BugAffectsPerson.bugID.is_in(dupe_bug_ids),1938 BugAffectsPerson.bug_id.is_in(dupe_bug_ids),
1939 ).set(affected=affected)1939 ).set(affected=affected)
1940 for dupe in self.duplicates:1940 for dupe in self.duplicates:
1941 dupe._flushAndInvalidate()1941 dupe._flushAndInvalidate()
@@ -2826,12 +2826,25 @@ class BugSet:
2826 Bug.heat_last_updated)2826 Bug.heat_last_updated)
28272827
28282828
2829class BugAffectsPerson(SQLBase):2829class BugAffectsPerson(StormBase):
2830 """A bug is marked as affecting a user."""2830 """A bug is marked as affecting a user."""
2831 bug = ForeignKey(dbName='bug', foreignKey='Bug', notNull=True)2831
2832 person = ForeignKey(dbName='person', foreignKey='Person', notNull=True)2832 __storm_table__ = 'BugAffectsPerson'
2833 affected = BoolCol(notNull=True, default=True)2833 __storm_primary__ = 'bug_id', 'person_id'
2834 __storm_primary__ = "bugID", "personID"2834
2835 bug_id = Int(name='bug', allow_none=False)
2836 bug = Reference(bug_id, 'Bug.id')
2837
2838 person_id = Int(name='person', allow_none=False)
2839 person = Reference(person_id, 'Person.id')
2840
2841 affected = Bool(allow_none=False, default=True)
2842
2843 def __init__(self, bug, person, affected=True):
2844 super(BugAffectsPerson, self).__init__()
2845 self.bug = bug
2846 self.person = person
2847 self.affected = affected
28352848
28362849
2837@implementer(IFileBugData)2850@implementer(IFileBugData)
diff --git a/lib/lp/bugs/model/bugtasksearch.py b/lib/lp/bugs/model/bugtasksearch.py
index 832dada..3335442 100644
--- a/lib/lp/bugs/model/bugtasksearch.py
+++ b/lib/lp/bugs/model/bugtasksearch.py
@@ -661,7 +661,7 @@ def _build_query(params):
661 join_tables.append(661 join_tables.append(
662 (BugAffectsPerson, Join(662 (BugAffectsPerson, Join(
663 BugAffectsPerson, And(663 BugAffectsPerson, And(
664 BugTaskFlat.bug_id == BugAffectsPerson.bugID,664 BugTaskFlat.bug_id == BugAffectsPerson.bug_id,
665 BugAffectsPerson.affected,665 BugAffectsPerson.affected,
666 BugAffectsPerson.person == params.affected_user))))666 BugAffectsPerson.person == params.affected_user))))
667667
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:
481481
482 if affected_by_bug:482 if affected_by_bug:
483 affected_clauses = [483 affected_clauses = [
484 BugAffectsPerson.personID == HWSubmission.ownerID,484 BugAffectsPerson.person_id == HWSubmission.ownerID,
485 BugAffectsPerson.bug == Bug.id,485 BugAffectsPerson.bug == Bug.id,
486 BugAffectsPerson.affected,486 BugAffectsPerson.affected,
487 ]487 ]
@@ -538,7 +538,7 @@ class HWSubmissionSet:
538 tables.append(BugSubscription)538 tables.append(BugSubscription)
539 if affected_by_bug:539 if affected_by_bug:
540 person_clauses.append(540 person_clauses.append(
541 And(BugAffectsPerson.personID == HWSubmission.ownerID,541 And(BugAffectsPerson.person_id == HWSubmission.ownerID,
542 BugAffectsPerson.bug == Bug.id,542 BugAffectsPerson.bug == Bug.id,
543 BugAffectsPerson.affected))543 BugAffectsPerson.affected))
544 tables.append(BugAffectsPerson)544 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):
156156
157 def test_gen_reload_queries_with_compound_primary_keys(self):157 def test_gen_reload_queries_with_compound_primary_keys(self):
158 # gen_reload_queries() does not like compound primary keys.158 # gen_reload_queries() does not like compound primary keys.
159 db_queries = bulk.gen_reload_queries([BugAffectsPerson()])159 bap = BugAffectsPerson(
160 bug=self.factory.makeBug(), person=self.factory.makePerson())
161 db_queries = bulk.gen_reload_queries([bap])
160 self.assertRaisesWithContent(162 self.assertRaisesWithContent(
161 AssertionError,163 AssertionError,
162 'Compound primary keys are not supported: BugAffectsPerson.',164 'Compound primary keys are not supported: BugAffectsPerson.',

Subscribers

People subscribed via source and target branches

to status/vote changes: