Merge lp:~stevenk/launchpad/dsd-invalid-versions into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 12696
Proposed branch: lp:~stevenk/launchpad/dsd-invalid-versions
Merge into: lp:launchpad
Diff against target: 70 lines (+40/-2)
2 files modified
lib/lp/registry/model/distroseriesdifference.py (+15/-2)
lib/lp/registry/tests/test_distroseriesdifference.py (+25/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/dsd-invalid-versions
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Steve Kowalik (community) Abstain
Review via email: mp+55461@code.launchpad.net

Commit message

[r=lifeless][bug=745444] Filter out invalid versions in DSD.getAncestry().

Description of the change

Filter out invalid versions from parsing the changelog, so that they don't try and get set as the base version.

Now that python-debian can reliably tell us which versions are invalid, use that to filter out invalid versions.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve
Revision history for this message
Steve Kowalik (stevenk) :
review: Abstain
Revision history for this message
Robert Collins (lifeless) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/distroseriesdifference.py'
2--- lib/lp/registry/model/distroseriesdifference.py 2011-03-29 16:23:49 +0000
3+++ lib/lp/registry/model/distroseriesdifference.py 2011-03-30 03:17:30 +0000
4@@ -9,7 +9,10 @@
5 'DistroSeriesDifference',
6 ]
7
8-from debian.changelog import Changelog
9+from debian.changelog import (
10+ Changelog,
11+ Version,
12+ )
13 from lazr.enum import DBItem
14 from storm.expr import Desc
15 from storm.locals import (
16@@ -201,7 +204,17 @@
17 """Return the version ancestry for the given SPR, or None."""
18 if spr.changelog is None:
19 return None
20- return set(Changelog(spr.changelog.read()).versions)
21+ versions = set()
22+ # It would be nicer to use .versions() here, but it won't catch the
23+ # ValueError from malformed versions, and we don't want them leaking
24+ # into the ancestry.
25+ for raw_version in Changelog(spr.changelog.read())._raw_versions():
26+ try:
27+ version = Version(raw_version)
28+ except ValueError:
29+ continue
30+ versions.add(version)
31+ return versions
32
33 def _getPackageDiffURL(self, package_diff):
34 """Check status and return URL if appropriate."""
35
36=== modified file 'lib/lp/registry/tests/test_distroseriesdifference.py'
37--- lib/lp/registry/tests/test_distroseriesdifference.py 2011-03-14 09:36:59 +0000
38+++ lib/lp/registry/tests/test_distroseriesdifference.py 2011-03-30 03:17:30 +0000
39@@ -466,6 +466,31 @@
40
41 self.assertEqual('1.1', ds_diff.base_version)
42
43+ def test_base_version_invalid(self):
44+ # If the maximum base version is invalid, it is discarded and not
45+ # set as the base version.
46+ derived_series = self.factory.makeDistroSeries(
47+ parent_series=self.factory.makeDistroSeries())
48+ source_package_name = self.factory.getOrMakeSourcePackageName('foo')
49+ # Create changelogs for both.
50+ changelog_lfa = self.factory.makeChangelog(
51+ 'foo', ['1:2.0-1', 'a1:1.8.8-070403-1~priv1', '1:1.7-1'])
52+ parent_changelog_lfa = self.factory.makeChangelog(
53+ 'foo', ['1:2.0-2', 'a1:1.8.8-070403-1~priv1', '1:1.7-1'])
54+ transaction.commit() # Yay, librarian.
55+
56+ ds_diff = self.factory.makeDistroSeriesDifference(
57+ derived_series=derived_series, source_package_name_str='foo',
58+ versions={
59+ 'derived': '1:2.0-1',
60+ 'parent': '1:2.0-2',
61+ },
62+ changelogs={
63+ 'derived': changelog_lfa,
64+ 'parent': parent_changelog_lfa})
65+
66+ self.assertEqual('1:1.7-1', ds_diff.base_version)
67+
68 def test_base_source_pub_none(self):
69 # None is simply returned if there is no base version.
70 ds_diff = self.factory.makeDistroSeriesDifference()