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
1=== modified file 'lib/lp/code/model/sourcepackagerecipebuild.py'
2--- lib/lp/code/model/sourcepackagerecipebuild.py 2010-09-16 12:27:46 +0000
3+++ lib/lp/code/model/sourcepackagerecipebuild.py 2010-09-21 19:07:47 +0000
4@@ -223,6 +223,11 @@
5 def destroySelf(self):
6 self._unqueueBuild()
7 store = Store.of(self)
8+ releases = store.find(
9+ SourcePackageRelease,
10+ SourcePackageRelease.source_package_recipe_build == self.id)
11+ for release in releases:
12+ release.source_package_recipe_build = None
13 store.remove(self)
14
15 @classmethod
16
17=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipe.py'
18--- lib/lp/code/model/tests/test_sourcepackagerecipe.py 2010-09-02 15:56:16 +0000
19+++ lib/lp/code/model/tests/test_sourcepackagerecipe.py 2010-09-21 19:07:47 +0000
20@@ -240,7 +240,8 @@
21 recipe_text = textwrap.dedent(recipe_text)
22 with person_logged_in(sp_recipe.owner):
23 self.assertRaises(
24- ForbiddenInstructionError, sp_recipe.setRecipeText, recipe_text)
25+ ForbiddenInstructionError, sp_recipe.setRecipeText,
26+ recipe_text)
27 self.assertEquals(
28 old_branches, list(sp_recipe.getReferencedBranches()))
29
30@@ -466,6 +467,19 @@
31 # Show no database constraints were violated
32 Store.of(recipe).flush()
33
34+ def test_destroySelf_clears_release(self):
35+ # Destroying a sourcepackagerecipe removes references to its builds
36+ # from their releases.
37+ recipe = self.factory.makeSourcePackageRecipe()
38+ build = self.factory.makeSourcePackageRecipeBuild(recipe=recipe)
39+ release = self.factory.makeSourcePackageRelease(
40+ source_package_recipe_build=build)
41+ self.assertEqual(build, release.source_package_recipe_build)
42+ with person_logged_in(recipe.owner):
43+ recipe.destroySelf()
44+ self.assertIs(None, release.source_package_recipe_build)
45+ transaction.commit()
46+
47 def test_findStaleDailyBuilds(self):
48 # Stale recipe not built daily.
49 self.factory.makeSourcePackageRecipe()
50
51=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipebuild.py'
52--- lib/lp/code/model/tests/test_sourcepackagerecipebuild.py 2010-09-16 12:27:46 +0000
53+++ lib/lp/code/model/tests/test_sourcepackagerecipebuild.py 2010-09-21 19:07:47 +0000
54@@ -291,6 +291,17 @@
55 build = self.factory.makeSourcePackageRecipeBuild()
56 build.destroySelf()
57
58+ def test_destroySelf_clears_release(self):
59+ # Destroying a sourcepackagerecipebuild removes references to it from
60+ # its releases.
61+ build = self.factory.makeSourcePackageRecipeBuild()
62+ release = self.factory.makeSourcePackageRelease(
63+ source_package_recipe_build=build)
64+ self.assertEqual(build, release.source_package_recipe_build)
65+ build.destroySelf()
66+ self.assertIs(None, release.source_package_recipe_build)
67+ transaction.commit()
68+
69 def test_cancelBuild(self):
70 # ISourcePackageRecipeBuild should make sure to remove jobs and build
71 # queue entries and then invalidate itself.