← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~abentley/launchpad/safe-delete-recipe-build into lp:launchpad/devel

 

Aaron Bentley has proposed merging lp:~abentley/launchpad/safe-delete-recipe-build into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #624815 Cannot delete a branch whose recipe build is referenced by a sourcepackagerelease
  https://bugs.launchpad.net/bugs/624815


= Summary =
Fix bug #624815: Cannot delete a branch whose recipe build is referenced by a
sourcepackagerelease

== Proposed fix ==
NULL the references to sourcepackagerecipebuilds when deleting them.

== Pre-implementation notes ==
None

== Implementation details ==
None

== Tests ==
bin/test -t destroySelf_clears_release

== Demo and Q/A ==
Create a sourcepackage recipe and build it.  Wait until it gets published.
Delete it.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/model/tests/test_sourcepackagerecipebuild.py
  lib/lp/code/model/tests/test_sourcepackagerecipe.py
  lib/lp/code/model/sourcepackagerecipebuild.py

./lib/lp/code/model/tests/test_sourcepackagerecipe.py
     257: E231 missing whitespace after ','
     281: E231 missing whitespace after ','
     289: E231 missing whitespace after ','
     296: E231 missing whitespace after ','
     304: E231 missing whitespace after ','
     342: E231 missing whitespace after ','
     402: E231 missing whitespace after ','
-- 
https://code.launchpad.net/~abentley/launchpad/safe-delete-recipe-build/+merge/36195
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~abentley/launchpad/safe-delete-recipe-build into lp:launchpad/devel.
=== modified file 'lib/lp/code/model/sourcepackagerecipebuild.py'
--- lib/lp/code/model/sourcepackagerecipebuild.py	2010-09-16 12:27:46 +0000
+++ lib/lp/code/model/sourcepackagerecipebuild.py	2010-09-21 19:07:47 +0000
@@ -223,6 +223,11 @@
     def destroySelf(self):
         self._unqueueBuild()
         store = Store.of(self)
+        releases = store.find(
+            SourcePackageRelease,
+            SourcePackageRelease.source_package_recipe_build == self.id)
+        for release in releases:
+            release.source_package_recipe_build = None
         store.remove(self)
 
     @classmethod

=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipe.py'
--- lib/lp/code/model/tests/test_sourcepackagerecipe.py	2010-09-02 15:56:16 +0000
+++ lib/lp/code/model/tests/test_sourcepackagerecipe.py	2010-09-21 19:07:47 +0000
@@ -240,7 +240,8 @@
         recipe_text = textwrap.dedent(recipe_text)
         with person_logged_in(sp_recipe.owner):
             self.assertRaises(
-                ForbiddenInstructionError, sp_recipe.setRecipeText, recipe_text)
+                ForbiddenInstructionError, sp_recipe.setRecipeText,
+                recipe_text)
         self.assertEquals(
             old_branches, list(sp_recipe.getReferencedBranches()))
 
@@ -466,6 +467,19 @@
         # Show no database constraints were violated
         Store.of(recipe).flush()
 
+    def test_destroySelf_clears_release(self):
+        # Destroying a sourcepackagerecipe removes references to its builds
+        # from their releases.
+        recipe = self.factory.makeSourcePackageRecipe()
+        build = self.factory.makeSourcePackageRecipeBuild(recipe=recipe)
+        release = self.factory.makeSourcePackageRelease(
+            source_package_recipe_build=build)
+        self.assertEqual(build, release.source_package_recipe_build)
+        with person_logged_in(recipe.owner):
+            recipe.destroySelf()
+        self.assertIs(None, release.source_package_recipe_build)
+        transaction.commit()
+
     def test_findStaleDailyBuilds(self):
         # Stale recipe not built daily.
         self.factory.makeSourcePackageRecipe()

=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipebuild.py'
--- lib/lp/code/model/tests/test_sourcepackagerecipebuild.py	2010-09-16 12:27:46 +0000
+++ lib/lp/code/model/tests/test_sourcepackagerecipebuild.py	2010-09-21 19:07:47 +0000
@@ -291,6 +291,17 @@
         build = self.factory.makeSourcePackageRecipeBuild()
         build.destroySelf()
 
+    def test_destroySelf_clears_release(self):
+        # Destroying a sourcepackagerecipebuild removes references to it from
+        # its releases.
+        build = self.factory.makeSourcePackageRecipeBuild()
+        release = self.factory.makeSourcePackageRelease(
+            source_package_recipe_build=build)
+        self.assertEqual(build, release.source_package_recipe_build)
+        build.destroySelf()
+        self.assertIs(None, release.source_package_recipe_build)
+        transaction.commit()
+
     def test_cancelBuild(self):
         # ISourcePackageRecipeBuild should make sure to remove jobs and build
         # queue entries and then invalidate itself.