Merge ~pappacena/launchpad:oci-recipe-cascade-delete-bugfix into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 0acec176975313619a2b0fd93949f487f19e8c58
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:oci-recipe-cascade-delete-bugfix
Merge into: launchpad:master
Diff against target: 74 lines (+9/-7)
3 files modified
lib/lp/oci/model/ocirecipe.py (+2/-2)
lib/lp/oci/tests/test_ocirecipe.py (+4/-2)
lib/lp/testing/factory.py (+3/-3)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+398711@code.launchpad.net

Commit message

LP: #1916605 - Fixing cascading deletion problem on OCIRecipe

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

LGTM, though could you adjust the commit message to use the form mentioned in https://help.launchpad.net/Code/Git#Linking_to_bugs since that's what I tend to search for when preparing deployments? I.e. "LP: #1916605" somewhere.

review: Approve
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

Changed the commit message. Landing this MP.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
2index 28ce8a0..e4edcae 100644
3--- a/lib/lp/oci/model/ocirecipe.py
4+++ b/lib/lp/oci/model/ocirecipe.py
5@@ -1,4 +1,4 @@
6-# Copyright 2019-2020 Canonical Ltd. This software is licensed under the
7+# Copyright 2019-2021 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """A recipe for building Open Container Initiative images."""
11@@ -253,9 +253,9 @@ class OCIRecipe(Storm, WebhookTargetMixin):
12 affected_jobs = Select(
13 [OCIRecipeJob.job_id],
14 And(OCIRecipeJob.job == Job.id, OCIRecipeJob.recipe == self))
15- store.find(Job, Job.id.is_in(affected_jobs)).remove()
16 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)
17 builds.remove()
18+ store.find(Job, Job.id.is_in(affected_jobs)).remove()
19 for push_rule in self.push_rules:
20 push_rule.destroySelf()
21 getUtility(IWebhookSet).delete(self.webhooks)
22diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
23index 3486d57..5335baa 100644
24--- a/lib/lp/oci/tests/test_ocirecipe.py
25+++ b/lib/lp/oci/tests/test_ocirecipe.py
26@@ -1,4 +1,4 @@
27-# Copyright 2019-2020 Canonical Ltd. This software is licensed under the
28+# Copyright 2019-2021 Canonical Ltd. This software is licensed under the
29 # GNU Affero General Public License version 3 (see the file LICENSE).
30
31 """Tests for OCI image building recipe functionality."""
32@@ -391,8 +391,10 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
33 self.setConfig()
34 oci_recipe = self.factory.makeOCIRecipe()
35 # Create associated builds:
36+ build_request = oci_recipe.requestBuilds(oci_recipe.owner, ["386"])
37 build_ids = [
38- self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id
39+ self.factory.makeOCIRecipeBuild(
40+ recipe=oci_recipe, build_request=build_request).id
41 for _ in range(3)]
42 # Create associated push rules:
43 push_rule_ids = [
44diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
45index 8577727..9661a8f 100644
46--- a/lib/lp/testing/factory.py
47+++ b/lib/lp/testing/factory.py
48@@ -2,7 +2,7 @@
49 # NOTE: The first line above must stay first; do not move the copyright
50 # notice to the top. See http://www.python.org/dev/peps/pep-0263/.
51 #
52-# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
53+# Copyright 2009-2021 Canonical Ltd. This software is licensed under the
54 # GNU Affero General Public License version 3 (see the file LICENSE).
55
56 """Testing infrastructure for the Launchpad application.
57@@ -4985,7 +4985,7 @@ class BareLaunchpadObjectFactory(ObjectFactory):
58 def makeOCIRecipeBuild(self, requester=None, registrant=None, recipe=None,
59 distro_arch_series=None, date_created=DEFAULT,
60 status=BuildStatus.NEEDSBUILD, builder=None,
61- duration=None, **kwargs):
62+ duration=None, build_request=None, **kwargs):
63 """Make a new OCIRecipeBuild."""
64 if requester is None:
65 requester = self.makePerson()
66@@ -5008,7 +5008,7 @@ class BareLaunchpadObjectFactory(ObjectFactory):
67 recipe = self.makeOCIRecipe(
68 registrant=registrant, oci_project=oci_project, **kwargs)
69 oci_build = getUtility(IOCIRecipeBuildSet).new(
70- requester, recipe, distro_arch_series, date_created)
71+ requester, recipe, distro_arch_series, date_created, build_request)
72 if duration is not None:
73 removeSecurityProxy(oci_build).updateStatus(
74 BuildStatus.BUILDING, builder=builder,