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
diff --git a/lib/lp/bugs/browser/bugcomment.py b/lib/lp/bugs/browser/bugcomment.py
index 2b61552..84be54e 100644
--- a/lib/lp/bugs/browser/bugcomment.py
+++ b/lib/lp/bugs/browser/bugcomment.py
@@ -123,10 +123,15 @@ def group_comments_with_activity(comments, activities):
123 (activity.datechanged, max_index,123 (activity.datechanged, max_index,
124 activity.person, activity_kind, activity)124 activity.person, activity_kind, activity)
125 for activity in activities)125 for activity in activities)
126
126 # when an action and a comment happen at the same time, the action comes127 # when an action and a comment happen at the same time, the action comes
127 # second, when two events are tied the comment index is used to128 # second, when two events are tied the comment index is used to
128 # disambiguate.129 # disambiguate.
129 events = sorted(chain(comments, activity), key=itemgetter(0, 1, 2))130 def event_sort_key(event):
131 date, index, person, _, _ = event
132 return date, index, person.id
133
134 events = sorted(chain(comments, activity), key=event_sort_key)
130135
131 def gen_event_windows(events):136 def gen_event_windows(events):
132 """Generate event windows.137 """Generate event windows.
diff --git a/lib/lp/bugs/browser/tests/test_bugcomment.py b/lib/lp/bugs/browser/tests/test_bugcomment.py
index c1877a5..f115b83 100644
--- a/lib/lp/bugs/browser/tests/test_bugcomment.py
+++ b/lib/lp/bugs/browser/tests/test_bugcomment.py
@@ -137,6 +137,17 @@ class TestGroupCommentsWithActivities(TestCase):
137 [[activity1], comment1, [activity2], comment2],137 [[activity1], comment1, [activity2], comment2],
138 self.group(comments=comments, activities=activities))138 self.group(comments=comments, activities=activities))
139139
140 def test_activities_identical_timestamp_no_common_actor(self):
141 # When two activities have an identical timestamp but different
142 # actors, no grouping is possible. (This can happen when a bug task
143 # was auto-confirmed due to multiple affected users; in that case
144 # the status change is ascribed to ~janitor.)
145 activity_time = next(self.time_index)[0]
146 activities = [BugActivityStub(activity_time) for _ in range(2)]
147 self.assertEqual(
148 [[activity] for activity in activities],
149 self.group(comments=[], activities=activities))
150
140 def test_comment_then_activity_close_by_common_actor(self):151 def test_comment_then_activity_close_by_common_actor(self):
141 # An activity shortly after a comment by the same person is grouped152 # An activity shortly after a comment by the same person is grouped
142 # into the comment.153 # into the comment.

Subscribers

People subscribed via source and target branches

to status/vote changes: