Merge ~cjwatson/launchpad:export-is-stale into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ef65c0428813fdf3526cce1e810a2841f98cb039
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:export-is-stale
Merge into: launchpad:master
Diff against target: 98 lines (+26/-5)
5 files modified
lib/lp/code/interfaces/sourcepackagerecipe.py (+3/-2)
lib/lp/code/model/gitrepository.py (+4/-1)
lib/lp/code/model/tests/test_sourcepackagerecipe.py (+8/-0)
lib/lp/snappy/interfaces/snap.py (+2/-2)
lib/lp/snappy/tests/test_snap.py (+9/-0)
Reviewer Review Type Date Requested Status
Ioana Lasc Approve
Review via email: mp+402642@code.launchpad.net

Commit message

Export read-only is_stale attribute on recipes

Description of the change

This is useful for debugging.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/interfaces/sourcepackagerecipe.py b/lib/lp/code/interfaces/sourcepackagerecipe.py
2index b499ccd..3d9d3ab 100644
3--- a/lib/lp/code/interfaces/sourcepackagerecipe.py
4+++ b/lib/lp/code/interfaces/sourcepackagerecipe.py
5@@ -1,4 +1,4 @@
6-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
7+# Copyright 2009-2021 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """Interface of the `SourcePackageRecipe` content type."""
11@@ -277,7 +277,8 @@ class ISourcePackageRecipeEditableAttributes(IHasOwner):
12 date_last_modified = exported(
13 Datetime(required=True, readonly=True))
14
15- is_stale = Bool(title=_('Recipe is stale.'))
16+ is_stale = exported(
17+ Bool(title=_('Recipe is stale.'), required=True, readonly=True))
18
19
20 class ISourcePackageRecipeEdit(Interface):
21diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
22index 2ba9491..d447abb 100644
23--- a/lib/lp/code/model/gitrepository.py
24+++ b/lib/lp/code/model/gitrepository.py
25@@ -1272,7 +1272,10 @@ class GitRepository(StormBase, WebhookTargetMixin, GitIdentityMixin):
26 paths=paths,
27 check_permissions=False)
28 for snap in snaps:
29- snap.is_stale = True
30+ # ISnapSet.findByGitRepository returns security-proxied Snap
31+ # objects on which the is_stale attribute is read-only. Bypass
32+ # this.
33+ removeSecurityProxy(snap).is_stale = True
34
35 def _markProposalMerged(self, proposal, merged_revision_id, logger=None):
36 if logger is not None:
37diff --git a/lib/lp/code/model/tests/test_sourcepackagerecipe.py b/lib/lp/code/model/tests/test_sourcepackagerecipe.py
38index 514521f..b14b8ab 100644
39--- a/lib/lp/code/model/tests/test_sourcepackagerecipe.py
40+++ b/lib/lp/code/model/tests/test_sourcepackagerecipe.py
41@@ -14,6 +14,7 @@ from datetime import (
42 import textwrap
43
44 from breezy.plugins.builder.recipe import ForbiddenInstructionError
45+from lazr.restfulclient.errors import BadRequest
46 from pytz import UTC
47 from storm.locals import Store
48 from testtools.matchers import Equals
49@@ -1232,6 +1233,13 @@ class TestWebserviceMixin:
50 recipe.setRecipeText(recipe_text=recipe_text2)
51 self.assertEqual(recipe_text2, recipe.recipe_text)
52
53+ def test_is_stale(self):
54+ """is_stale is exported and is read-only."""
55+ recipe = self.makeRecipe()[0]
56+ self.assertTrue(recipe.is_stale)
57+ recipe.is_stale = False
58+ self.assertRaises(BadRequest, recipe.lp_save)
59+
60 def test_getRecipe(self):
61 """Person.getRecipe returns the named recipe."""
62 recipe, user = self.makeRecipe()[:-1]
63diff --git a/lib/lp/snappy/interfaces/snap.py b/lib/lp/snappy/interfaces/snap.py
64index f2ce156..16fd213 100644
65--- a/lib/lp/snappy/interfaces/snap.py
66+++ b/lib/lp/snappy/interfaces/snap.py
67@@ -827,9 +827,9 @@ class ISnapEditableAttributes(IHasOwner):
68 "this snap package. Currently only 'core', 'core18', "
69 "'core20' and 'snapcraft' keys are supported.")))
70
71- is_stale = Bool(
72+ is_stale = exported(Bool(
73 title=_("Snap package is stale and is due to be rebuilt."),
74- required=True, readonly=False)
75+ required=True, readonly=True))
76
77 store_upload = exported(Bool(
78 title=_("Automatically upload to store"),
79diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
80index be338d7..bb6c659 100644
81--- a/lib/lp/snappy/tests/test_snap.py
82+++ b/lib/lp/snappy/tests/test_snap.py
83@@ -3039,6 +3039,15 @@ class TestSnapWebservice(TestCaseWithFactory):
84 "git_path": Equals("HEAD"),
85 }))
86
87+ def test_is_stale(self):
88+ # is_stale is exported and is read-only.
89+ snap = self.makeSnap()
90+ self.assertTrue(snap["is_stale"])
91+ response = self.webservice.patch(
92+ snap["self_link"], "application/json",
93+ json.dumps({"is_stale": False}))
94+ self.assertEqual(400, response.status)
95+
96 def test_getByName(self):
97 # lp.snaps.getByName returns a matching Snap.
98 snap = self.makeSnap()

Subscribers

People subscribed via source and target branches

to status/vote changes: