Merge lp:~cjwatson/launchpad/mp-job-delete-bug-link into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18387
Proposed branch: lp:~cjwatson/launchpad/mp-job-delete-bug-link
Merge into: lp:launchpad
Diff against target: 136 lines (+31/-23)
5 files modified
database/schema/security.cfg (+1/-1)
lib/lp/code/model/branchmergeproposal.py (+15/-13)
lib/lp/code/model/tests/test_branchmergeproposal.py (+3/-6)
lib/lp/code/model/tests/test_branchmergeproposaljobs.py (+10/-1)
lib/lp/code/tests/helpers.py (+2/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/mp-job-delete-bug-link
Reviewer Review Type Date Requested Status
William Grant Approve
Review via email: mp+324323@code.launchpad.net

Commit message

Fix crash when unlinking a bug from a Git-based MP in UpdatePreviewDiffJob.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2017-04-08 16:58:52 +0000
3+++ database/schema/security.cfg 2017-05-19 16:07:20 +0000
4@@ -2018,7 +2018,7 @@
5 public.validpersoncache = SELECT
6 public.webhook = SELECT
7 public.webhookjob = SELECT, INSERT
8-public.xref = SELECT, INSERT
9+public.xref = SELECT, INSERT, DELETE
10 type=user
11
12 [sharing-jobs]
13
14=== modified file 'lib/lp/code/model/branchmergeproposal.py'
15--- lib/lp/code/model/branchmergeproposal.py 2016-09-09 12:37:25 +0000
16+++ lib/lp/code/model/branchmergeproposal.py 2017-05-19 16:07:20 +0000
17@@ -1,4 +1,4 @@
18-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
19+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
20 # GNU Affero General Public License version 3 (see the file LICENSE).
21
22 """Database class for branch merge proposals."""
23@@ -500,19 +500,21 @@
24 remove_bugs = load(Bug, set(
25 bug_id for bug_id in current_bug_ids - new_bug_ids
26 if current_bug_ids_from_source[bug_id]))
27- for bug in remove_bugs:
28- self.unlinkBug(bug, check_permissions=False)
29 add_bugs = load(Bug, new_bug_ids - current_bug_ids)
30- # XXX cjwatson 2016-06-11: We could perhaps set creator and
31- # date_created based on commit information, but then we'd have to
32- # work out what to do in the case of multiple commits referring to
33- # the same bug, updating properties if more such commits arrive
34- # later, etc. This is simple and does the job for now.
35- for bug in add_bugs:
36- self.linkBug(
37- bug, user=getUtility(ILaunchpadCelebrities).janitor,
38- check_permissions=False,
39- props={'metadata': {'from_source': True}})
40+ if remove_bugs or add_bugs:
41+ janitor = getUtility(ILaunchpadCelebrities).janitor
42+ for bug in remove_bugs:
43+ self.unlinkBug(bug, user=janitor, check_permissions=False)
44+ # XXX cjwatson 2016-06-11: We could perhaps set creator and
45+ # date_created based on commit information, but then we'd have
46+ # to work out what to do in the case of multiple commits
47+ # referring to the same bug, updating properties if more such
48+ # commits arrive later, etc. This is simple and does the job
49+ # for now.
50+ for bug in add_bugs:
51+ self.linkBug(
52+ bug, user=janitor, check_permissions=False,
53+ props={'metadata': {'from_source': True}})
54
55 @property
56 def address(self):
57
58=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
59--- lib/lp/code/model/tests/test_branchmergeproposal.py 2016-11-09 17:18:21 +0000
60+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2017-05-19 16:07:20 +0000
61@@ -1,4 +1,4 @@
62-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
63+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
64 # GNU Affero General Public License version 3 (see the file LICENSE).
65
66 """Tests for BranchMergeProposals."""
67@@ -80,7 +80,6 @@
68 from lp.services.config import config
69 from lp.services.database.constants import UTC_NOW
70 from lp.services.features.testing import FeatureFixture
71-from lp.services.memcache.testing import MemcacheFixture
72 from lp.services.webapp import canonical_url
73 from lp.services.xref.interfaces import IXRefSet
74 from lp.testing import (
75@@ -1486,9 +1485,7 @@
76
77 def setUp(self):
78 super(TestBranchMergeProposalBugsGit, self).setUp()
79- self.hosting_fixture = self.useFixture(GitHostingFixture(
80- disable_memcache=False))
81- self.memcache_fixture = self.useFixture(MemcacheFixture())
82+ self.hosting_fixture = self.useFixture(GitHostingFixture())
83
84 def _makeBranchMergeProposal(self):
85 return self.factory.makeBranchMergeProposalForGit()
86@@ -1537,7 +1534,7 @@
87 u"message": u"LP: #%d" % bug.id,
88 }
89 for i, bug in enumerate(bugs)]
90- self.memcache_fixture.clear()
91+ self.hosting_fixture.memcache_fixture.clear()
92
93 def test_updateRelatedBugsFromSource_no_links(self):
94 # updateRelatedBugsFromSource does nothing if there are no related
95
96=== modified file 'lib/lp/code/model/tests/test_branchmergeproposaljobs.py'
97--- lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2016-10-02 00:33:51 +0000
98+++ lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2017-05-19 16:07:20 +0000
99@@ -1,4 +1,4 @@
100-# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
101+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
102 # GNU Affero General Public License version 3 (see the file LICENSE).
103
104 """Tests for branch merge proposal jobs."""
105@@ -284,6 +284,15 @@
106 self.assertEqual([bug], bmp.bugs)
107 self.assertEqual([bmp], bug.linked_merge_proposals)
108 self.assertEqual(patch, bmp.preview_diff.text)
109+ # If somebody rewrites history to remove the bug reference, then the
110+ # bug link is removed from the merge proposal.
111+ self.hosting_fixture.getLog.result = []
112+ self.hosting_fixture.memcache_fixture.clear()
113+ job = UpdatePreviewDiffJob.create(bmp)
114+ with dbuser("merge-proposal-jobs"):
115+ JobRunner([job]).runAll()
116+ self.assertEqual([], bmp.bugs)
117+ self.assertEqual([], bug.linked_merge_proposals)
118
119 def test_run_object_events(self):
120 # While the job runs a single IObjectModifiedEvent is issued when the
121
122=== modified file 'lib/lp/code/tests/helpers.py'
123--- lib/lp/code/tests/helpers.py 2016-10-11 14:26:31 +0000
124+++ lib/lp/code/tests/helpers.py 2017-05-19 16:07:20 +0000
125@@ -1,4 +1,4 @@
126-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
127+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
128 # GNU Affero General Public License version 3 (see the file LICENSE).
129
130 """Helper functions for code testing live here."""
131@@ -331,4 +331,4 @@
132 # makes it awkward to repeat the same call with different log
133 # responses. For convenience, we make it easy to disable that
134 # here.
135- self.useFixture(MemcacheFixture())
136+ self.memcache_fixture = self.useFixture(MemcacheFixture())