Merge lp:~abentley/launchpad/mark-dup-empty into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 13557
Proposed branch: lp:~abentley/launchpad/mark-dup-empty
Merge into: lp:launchpad
Diff against target: 42 lines (+13/-1)
2 files modified
lib/lp/bugs/model/bug.py (+2/-1)
lib/lp/bugs/model/tests/test_bug.py (+11/-0)
To merge this branch: bzr merge lp:~abentley/launchpad/mark-dup-empty
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+69704@code.launchpad.net

Commit message

No AttributeError marking a bug as not a dupe.

Description of the change

= Summary =
Fix bug #811262: AttributeError: 'NoneType' object has no attribute 'updateHeat'

== Proposed fix ==
Do not assume that the current duplicate is non-None if markAsDuplicate is called with None.

== Pre-implementation notes ==
None

== Implementation details ==
The code assumed the bug must be a duplicate if markAsDuplicate(None) was called. I changed it to check for None.

== Tests ==
bin/test test_bug -t markAsD

== Demo and Q/A ==
Go to a bug's mark-as-duplicate page for a bug that is not alredy marked as a duplicate. Don't enter a value, and hit 'Change'. You should not get an oops.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/model/tests/test_bug.py
  lib/lp/bugs/model/bug.py

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Good fix.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/model/bug.py'
2--- lib/lp/bugs/model/bug.py 2011-07-22 00:28:34 +0000
3+++ lib/lp/bugs/model/bug.py 2011-07-28 18:34:31 +0000
4@@ -1863,7 +1863,8 @@
5 # from having been a duplicate. We also update the bug that
6 # was previously duplicated.
7 self.updateHeat(affected_targets)
8- current_duplicateof.updateHeat(affected_targets)
9+ if current_duplicateof is not None:
10+ current_duplicateof.updateHeat(affected_targets)
11 return affected_targets
12
13 def markAsDuplicate(self, duplicate_of):
14
15=== modified file 'lib/lp/bugs/model/tests/test_bug.py'
16--- lib/lp/bugs/model/tests/test_bug.py 2011-07-22 00:28:34 +0000
17+++ lib/lp/bugs/model/tests/test_bug.py 2011-07-28 18:34:31 +0000
18@@ -3,6 +3,8 @@
19
20 __metaclass__ = type
21
22+from testtools.testcase import ExpectedException
23+
24 from canonical.testing.layers import DatabaseFunctionalLayer
25 from lp.bugs.enum import BugNotificationLevel
26 from lp.bugs.interfaces.bugtask import BugTaskStatus
27@@ -21,6 +23,15 @@
28
29 layer = DatabaseFunctionalLayer
30
31+ def test_markAsDuplicate_None(self):
32+ # Calling markAsDuplicate(None) on a bug that is not currently a
33+ # duplicate works correctly, and does not raise an AttributeError.
34+ bug = self.factory.makeBug()
35+ with ExpectedException(AssertionError, 'AttributeError not raised'):
36+ with ExpectedException(AttributeError, ''):
37+ with person_logged_in(self.factory.makePerson()):
38+ bug.markAsDuplicate(None)
39+
40 def test_get_subscribers_for_person_unsubscribed(self):
41 bug = self.factory.makeBug()
42 person = self.factory.makePerson()