Merge lp:~jcsackett/launchpad/620494-downloads-sort into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: 11435
Proposed branch: lp:~jcsackett/launchpad/620494-downloads-sort
Merge into: lp:launchpad
Diff against target: 69 lines (+40/-1)
2 files modified
lib/lp/registry/model/product.py (+8/-1)
lib/lp/registry/tests/test_product.py (+32/-0)
To merge this branch: bzr merge lp:~jcsackett/launchpad/620494-downloads-sort
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+33413@code.launchpad.net

Commit message

Fixes sorting on plus download by adding milestone name as an additional sort parameter.

Description of the change

= Summary =

Fixes an edge case sorting releases on +download by adding an additional sort field. Per the bug, if too releases have the same date, they can be sorted wrong from the fallback to database id.

== Proposed fix ==

Add an additional sort by milestone.name; this catches the edge case and displays the releases correctly since most milestones use numeric names.

== Pre-implementation notes ==

Talked with Curtis.

== Implementation details ==

As in Proposed fix.

== Tests ==

bin/test -vvc -t getMilestonesAndReleases

== Demo and Q/A ==

On Thunderbird in dev (launchpad.dev/thunderbird) create two releases on trunk with milestones 0.99 and 0.98; make sure they have downloadable files. On http://launchpad.dev/thunderbird/+download you should see 0.99 listed before 0.98.

= Launchpad lint =
Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/model/product.py
  lib/lp/registry/tests/test_product.py

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

I think that someone is adding a database sort function for milestone
names anyhow; you should probably use that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/product.py'
2--- lib/lp/registry/model/product.py 2010-08-22 19:26:46 +0000
3+++ lib/lp/registry/model/product.py 2010-08-24 14:48:47 +0000
4@@ -1122,6 +1122,11 @@
5 And(Milestone.product == self,
6 Milestone.name == version)).one()
7
8+ # XXX: jcsackett 2010-08-23 bug=620494
9+ # The second clause in the order_by in this method is a bandaid
10+ # on a sorting issue caused by date vs datetime conflicts in the
11+ # database. A fix is coming out, but this deals with the edge
12+ # case responsible for the referenced bug.
13 def getMilestonesAndReleases(self):
14 """See `IProduct`."""
15 store = Store.of(self)
16@@ -1130,7 +1135,9 @@
17 And(ProductRelease.milestone == Milestone.id,
18 Milestone.productseries == ProductSeries.id,
19 ProductSeries.product == self))
20- return result.order_by(Desc(ProductRelease.datereleased))
21+ return result.order_by(
22+ Desc(ProductRelease.datereleased),
23+ Desc(Milestone.name))
24
25 def packagedInDistros(self):
26 return IStore(Distribution).find(
27
28=== modified file 'lib/lp/registry/tests/test_product.py'
29--- lib/lp/registry/tests/test_product.py 2010-08-22 19:26:46 +0000
30+++ lib/lp/registry/tests/test_product.py 2010-08-24 14:48:47 +0000
31@@ -60,6 +60,38 @@
32 product.active = False
33 self.assertEqual(False, product.active)
34
35+ def test_milestone_sorting_getMilestonesAndReleases(self):
36+ product = self.factory.makeProduct()
37+ series = self.factory.makeProductSeries(product=product)
38+ milestone_0_1 = self.factory.makeMilestone(
39+ product=product,
40+ productseries=series,
41+ name='0.1')
42+ milestone_0_2 = self.factory.makeMilestone(
43+ product=product,
44+ productseries=series,
45+ name='0.2')
46+ release_1 = self.factory.makeProductRelease(
47+ product=product,
48+ milestone=milestone_0_1)
49+ release_2 = self.factory.makeProductRelease(
50+ product=product,
51+ milestone=milestone_0_2)
52+ release_file1 = self.factory.makeProductReleaseFile(
53+ product=product,
54+ release=release_1,
55+ productseries=series,
56+ milestone=milestone_0_1)
57+ release_file2 = self.factory.makeProductReleaseFile(
58+ product=product,
59+ release=release_2,
60+ productseries=series,
61+ milestone=milestone_0_2)
62+ expected = [(milestone_0_2, release_2), (milestone_0_1, release_1)]
63+ self.assertEqual(
64+ expected,
65+ list(product.getMilestonesAndReleases()))
66+
67
68 class TestProductFiles(unittest.TestCase):
69 """Tests for downloadable product files."""