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

Proposed by Aaron Bentley
Status: Merged
Approved by: Paul Hummer
Approved revision: no longer in the source branch.
Merged at revision: 11598
Proposed branch: lp:~abentley/launchpad/safe-delete-recipe-build
Merge into: lp:launchpad
Diff against target: 71 lines (+31/-1)
3 files modified
lib/lp/code/model/sourcepackagerecipebuild.py (+5/-0)
lib/lp/code/model/tests/test_sourcepackagerecipe.py (+15/-1)
lib/lp/code/model/tests/test_sourcepackagerecipebuild.py (+11/-0)
To merge this branch: bzr merge lp:~abentley/launchpad/safe-delete-recipe-build
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Review via email: mp+36195@code.launchpad.net

Commit message

Fix bug deleting recipe builds that have releases.

Description of the change

= 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 ','

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
223 def destroySelf(self):223 def destroySelf(self):
224 self._unqueueBuild()224 self._unqueueBuild()
225 store = Store.of(self)225 store = Store.of(self)
226 releases = store.find(
227 SourcePackageRelease,
228 SourcePackageRelease.source_package_recipe_build == self.id)
229 for release in releases:
230 release.source_package_recipe_build = None
226 store.remove(self)231 store.remove(self)
227232
228 @classmethod233 @classmethod
229234
=== 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 @@
240 recipe_text = textwrap.dedent(recipe_text)240 recipe_text = textwrap.dedent(recipe_text)
241 with person_logged_in(sp_recipe.owner):241 with person_logged_in(sp_recipe.owner):
242 self.assertRaises(242 self.assertRaises(
243 ForbiddenInstructionError, sp_recipe.setRecipeText, recipe_text)243 ForbiddenInstructionError, sp_recipe.setRecipeText,
244 recipe_text)
244 self.assertEquals(245 self.assertEquals(
245 old_branches, list(sp_recipe.getReferencedBranches()))246 old_branches, list(sp_recipe.getReferencedBranches()))
246247
@@ -466,6 +467,19 @@
466 # Show no database constraints were violated467 # Show no database constraints were violated
467 Store.of(recipe).flush()468 Store.of(recipe).flush()
468469
470 def test_destroySelf_clears_release(self):
471 # Destroying a sourcepackagerecipe removes references to its builds
472 # from their releases.
473 recipe = self.factory.makeSourcePackageRecipe()
474 build = self.factory.makeSourcePackageRecipeBuild(recipe=recipe)
475 release = self.factory.makeSourcePackageRelease(
476 source_package_recipe_build=build)
477 self.assertEqual(build, release.source_package_recipe_build)
478 with person_logged_in(recipe.owner):
479 recipe.destroySelf()
480 self.assertIs(None, release.source_package_recipe_build)
481 transaction.commit()
482
469 def test_findStaleDailyBuilds(self):483 def test_findStaleDailyBuilds(self):
470 # Stale recipe not built daily.484 # Stale recipe not built daily.
471 self.factory.makeSourcePackageRecipe()485 self.factory.makeSourcePackageRecipe()
472486
=== 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 @@
291 build = self.factory.makeSourcePackageRecipeBuild()291 build = self.factory.makeSourcePackageRecipeBuild()
292 build.destroySelf()292 build.destroySelf()
293293
294 def test_destroySelf_clears_release(self):
295 # Destroying a sourcepackagerecipebuild removes references to it from
296 # its releases.
297 build = self.factory.makeSourcePackageRecipeBuild()
298 release = self.factory.makeSourcePackageRelease(
299 source_package_recipe_build=build)
300 self.assertEqual(build, release.source_package_recipe_build)
301 build.destroySelf()
302 self.assertIs(None, release.source_package_recipe_build)
303 transaction.commit()
304
294 def test_cancelBuild(self):305 def test_cancelBuild(self):
295 # ISourcePackageRecipeBuild should make sure to remove jobs and build306 # ISourcePackageRecipeBuild should make sure to remove jobs and build
296 # queue entries and then invalidate itself.307 # queue entries and then invalidate itself.