Merge ~cjwatson/launchpad:py3-group-bug-comments into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c1e52004b0958a46690d3ba9459d1d27f46fc739
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-group-bug-comments
Merge into: launchpad:master
Diff against target: 43 lines (+17/-1)
2 files modified
lib/lp/bugs/browser/bugcomment.py (+6/-1)
lib/lp/bugs/browser/tests/test_bugcomment.py (+11/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+402636@code.launchpad.net

Commit message

Fix sorting of bug activities on Python 3

Description of the change

In some cases (auto-confirmation of bug tasks) it's possible for a bug to have multiple activities with the same timestamp but different actors, and that caused an OOPS when trying to render such bugs on Python 3. Fix the tie-breaking condition.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/browser/bugcomment.py b/lib/lp/bugs/browser/bugcomment.py
2index 2b61552..84be54e 100644
3--- a/lib/lp/bugs/browser/bugcomment.py
4+++ b/lib/lp/bugs/browser/bugcomment.py
5@@ -123,10 +123,15 @@ def group_comments_with_activity(comments, activities):
6 (activity.datechanged, max_index,
7 activity.person, activity_kind, activity)
8 for activity in activities)
9+
10 # when an action and a comment happen at the same time, the action comes
11 # second, when two events are tied the comment index is used to
12 # disambiguate.
13- events = sorted(chain(comments, activity), key=itemgetter(0, 1, 2))
14+ def event_sort_key(event):
15+ date, index, person, _, _ = event
16+ return date, index, person.id
17+
18+ events = sorted(chain(comments, activity), key=event_sort_key)
19
20 def gen_event_windows(events):
21 """Generate event windows.
22diff --git a/lib/lp/bugs/browser/tests/test_bugcomment.py b/lib/lp/bugs/browser/tests/test_bugcomment.py
23index c1877a5..f115b83 100644
24--- a/lib/lp/bugs/browser/tests/test_bugcomment.py
25+++ b/lib/lp/bugs/browser/tests/test_bugcomment.py
26@@ -137,6 +137,17 @@ class TestGroupCommentsWithActivities(TestCase):
27 [[activity1], comment1, [activity2], comment2],
28 self.group(comments=comments, activities=activities))
29
30+ def test_activities_identical_timestamp_no_common_actor(self):
31+ # When two activities have an identical timestamp but different
32+ # actors, no grouping is possible. (This can happen when a bug task
33+ # was auto-confirmed due to multiple affected users; in that case
34+ # the status change is ascribed to ~janitor.)
35+ activity_time = next(self.time_index)[0]
36+ activities = [BugActivityStub(activity_time) for _ in range(2)]
37+ self.assertEqual(
38+ [[activity] for activity in activities],
39+ self.group(comments=[], activities=activities))
40+
41 def test_comment_then_activity_close_by_common_actor(self):
42 # An activity shortly after a comment by the same person is grouped
43 # into the comment.

Subscribers

People subscribed via source and target branches

to status/vote changes: