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
diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
index 28ce8a0..e4edcae 100644
--- a/lib/lp/oci/model/ocirecipe.py
+++ b/lib/lp/oci/model/ocirecipe.py
@@ -1,4 +1,4 @@
1# Copyright 2019-2020 Canonical Ltd. This software is licensed under the1# Copyright 2019-2021 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""A recipe for building Open Container Initiative images."""4"""A recipe for building Open Container Initiative images."""
@@ -253,9 +253,9 @@ class OCIRecipe(Storm, WebhookTargetMixin):
253 affected_jobs = Select(253 affected_jobs = Select(
254 [OCIRecipeJob.job_id],254 [OCIRecipeJob.job_id],
255 And(OCIRecipeJob.job == Job.id, OCIRecipeJob.recipe == self))255 And(OCIRecipeJob.job == Job.id, OCIRecipeJob.recipe == self))
256 store.find(Job, Job.id.is_in(affected_jobs)).remove()
257 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)256 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)
258 builds.remove()257 builds.remove()
258 store.find(Job, Job.id.is_in(affected_jobs)).remove()
259 for push_rule in self.push_rules:259 for push_rule in self.push_rules:
260 push_rule.destroySelf()260 push_rule.destroySelf()
261 getUtility(IWebhookSet).delete(self.webhooks)261 getUtility(IWebhookSet).delete(self.webhooks)
diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
index 3486d57..5335baa 100644
--- a/lib/lp/oci/tests/test_ocirecipe.py
+++ b/lib/lp/oci/tests/test_ocirecipe.py
@@ -1,4 +1,4 @@
1# Copyright 2019-2020 Canonical Ltd. This software is licensed under the1# Copyright 2019-2021 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for OCI image building recipe functionality."""4"""Tests for OCI image building recipe functionality."""
@@ -391,8 +391,10 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
391 self.setConfig()391 self.setConfig()
392 oci_recipe = self.factory.makeOCIRecipe()392 oci_recipe = self.factory.makeOCIRecipe()
393 # Create associated builds:393 # Create associated builds:
394 build_request = oci_recipe.requestBuilds(oci_recipe.owner, ["386"])
394 build_ids = [395 build_ids = [
395 self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id396 self.factory.makeOCIRecipeBuild(
397 recipe=oci_recipe, build_request=build_request).id
396 for _ in range(3)]398 for _ in range(3)]
397 # Create associated push rules:399 # Create associated push rules:
398 push_rule_ids = [400 push_rule_ids = [
diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
index 8577727..9661a8f 100644
--- a/lib/lp/testing/factory.py
+++ b/lib/lp/testing/factory.py
@@ -2,7 +2,7 @@
2# NOTE: The first line above must stay first; do not move the copyright2# NOTE: The first line above must stay first; do not move the copyright
3# notice to the top. See http://www.python.org/dev/peps/pep-0263/.3# notice to the top. See http://www.python.org/dev/peps/pep-0263/.
4#4#
5# Copyright 2009-2020 Canonical Ltd. This software is licensed under the5# Copyright 2009-2021 Canonical Ltd. This software is licensed under the
6# GNU Affero General Public License version 3 (see the file LICENSE).6# GNU Affero General Public License version 3 (see the file LICENSE).
77
8"""Testing infrastructure for the Launchpad application.8"""Testing infrastructure for the Launchpad application.
@@ -4985,7 +4985,7 @@ class BareLaunchpadObjectFactory(ObjectFactory):
4985 def makeOCIRecipeBuild(self, requester=None, registrant=None, recipe=None,4985 def makeOCIRecipeBuild(self, requester=None, registrant=None, recipe=None,
4986 distro_arch_series=None, date_created=DEFAULT,4986 distro_arch_series=None, date_created=DEFAULT,
4987 status=BuildStatus.NEEDSBUILD, builder=None,4987 status=BuildStatus.NEEDSBUILD, builder=None,
4988 duration=None, **kwargs):4988 duration=None, build_request=None, **kwargs):
4989 """Make a new OCIRecipeBuild."""4989 """Make a new OCIRecipeBuild."""
4990 if requester is None:4990 if requester is None:
4991 requester = self.makePerson()4991 requester = self.makePerson()
@@ -5008,7 +5008,7 @@ class BareLaunchpadObjectFactory(ObjectFactory):
5008 recipe = self.makeOCIRecipe(5008 recipe = self.makeOCIRecipe(
5009 registrant=registrant, oci_project=oci_project, **kwargs)5009 registrant=registrant, oci_project=oci_project, **kwargs)
5010 oci_build = getUtility(IOCIRecipeBuildSet).new(5010 oci_build = getUtility(IOCIRecipeBuildSet).new(
5011 requester, recipe, distro_arch_series, date_created)5011 requester, recipe, distro_arch_series, date_created, build_request)
5012 if duration is not None:5012 if duration is not None:
5013 removeSecurityProxy(oci_build).updateStatus(5013 removeSecurityProxy(oci_build).updateStatus(
5014 BuildStatus.BUILDING, builder=builder,5014 BuildStatus.BUILDING, builder=builder,