Merge lp:~jcsackett/launchpad/dsp-vocab-is-a-pain into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 13774
Proposed branch: lp:~jcsackett/launchpad/dsp-vocab-is-a-pain
Merge into: lp:launchpad
Prerequisite: lp:~jcsackett/launchpad/fix-picker-entry-adapters
Diff against target: 103 lines (+23/-8)
3 files modified
lib/lp/registry/adapters.py (+1/-1)
lib/lp/registry/model/distributionsourcepackage.py (+1/-0)
lib/lp/registry/vocabularies.py (+21/-7)
To merge this branch: bzr merge lp:~jcsackett/launchpad/dsp-vocab-is-a-pain
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+72217@code.launchpad.net

Commit message

[r=sinzui][bug=820005][incr] Updates dsp vocab to use the dsp in db in the search query.

Description of the change

Summary
=======
We want the dsp vocab to actually use DSPs. This means updating the vocab to use DistributionSourcePackageInDatabase as part of the search query.

Proposed Fix
============
Update the query to use DistributionSourcePackageInDatabase.

Preimplementation
=================
Spoke with Curtis Hovey.

Implementation
==============
lib/lp/registry/adapters.py
---------------------------
Drive by fix of a typo.

lib/lp/registry/vocabularies.py
lib/lp/registry/model/distributionsourcepackage.py
--------------------------------------------------
DistributionSourcePackageInDatabase is now used in the vocab's query; it also provides the link to Distribution, so DistroSeries is removed from the query. toTerm is updated to deal with producing a dsp term from the dsp-in-db; handling of proper dsps and spns is left alone.

LaunchpadTargetWidget may need to be updated; however as this vocab is behind a disabled feature flag (because it still has bugs barring it from being turned on) the update will be done in a separate branch to keep the work clear. Initial investigation shows that the the target widget can handle dsps -- since toTerm still returns dsps (as opposed to dsp in db), it should be fine.

Tests
=====
bin/test -vvct dsp_vocab

QA
==
With feature flag enabled, confirm that the package picker on retargeting answers works. Do not check on bug retargeting -- the dsp vocab is broken for that use in devel, and this branch has not fixed it. Make sure to disable the flag after QA.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/adapters.py
  lib/lp/registry/vocabularies.py
  lib/lp/registry/model/distributionsourcepackage.py

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you. I am happy to see this land.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/adapters.py'
2--- lib/lp/registry/adapters.py 2011-07-25 19:21:49 +0000
3+++ lib/lp/registry/adapters.py 2011-08-22 14:35:39 +0000
4@@ -1,7 +1,7 @@
5 # Copyright 2009 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8-"""Adapters for regisrty objects."""
9+"""Adapters for registry objects."""
10
11 __metaclass__ = type
12
13
14=== modified file 'lib/lp/registry/model/distributionsourcepackage.py'
15--- lib/lp/registry/model/distributionsourcepackage.py 2011-06-22 06:28:38 +0000
16+++ lib/lp/registry/model/distributionsourcepackage.py 2011-08-22 14:35:39 +0000
17@@ -9,6 +9,7 @@
18
19 __all__ = [
20 'DistributionSourcePackage',
21+ 'DistributionSourcePackageInDatabase',
22 ]
23
24 import itertools
25
26=== modified file 'lib/lp/registry/vocabularies.py'
27--- lib/lp/registry/vocabularies.py 2011-08-22 14:35:38 +0000
28+++ lib/lp/registry/vocabularies.py 2011-08-22 14:35:39 +0000
29@@ -131,6 +131,7 @@
30 SQLObjectVocabularyBase,
31 VocabularyFilter,
32 )
33+from canonical.lazr.utils import safe_hasattr
34 from lp.app.browser.tales import DateTimeFormatterAPI
35 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
36 from lp.blueprints.interfaces.specification import ISpecification
37@@ -173,7 +174,11 @@
38 from lp.registry.interfaces.productseries import IProductSeries
39 from lp.registry.interfaces.projectgroup import IProjectGroup
40 from lp.registry.interfaces.sourcepackage import ISourcePackage
41+from lp.registry.interfaces.sourcepackagename import ISourcePackageName
42 from lp.registry.model.distribution import Distribution
43+from lp.registry.model.distributionsourcepackage import (
44+ DistributionSourcePackageInDatabase,
45+ )
46 from lp.registry.model.distroseries import DistroSeries
47 from lp.registry.model.distroseriesdifference import DistroSeriesDifference
48 from lp.registry.model.distroseriesparent import DistroSeriesParent
49@@ -2186,6 +2191,14 @@
50 if IDistributionSourcePackage.providedBy(spn_or_dsp):
51 dsp = spn_or_dsp
52 distribution = spn_or_dsp.distribution
53+ elif (not ISourcePackageName.providedBy(spn_or_dsp) and
54+ safe_hasattr(spn_or_dsp, 'distribution')
55+ and safe_hasattr(spn_or_dsp, 'sourcepackagename')):
56+ # We use the hasattr checks rather than adaption because the
57+ # DistributionSourcePackageInDatabase object is a little bit
58+ # broken, and does not provide any interface.
59+ distribution = spn_or_dsp.distribution
60+ dsp = distribution.getSourcePackage(spn_or_dsp.sourcepackagename)
61 else:
62 distribution = distribution or self.distribution
63 if distribution is not None and spn_or_dsp is not None:
64@@ -2224,7 +2237,7 @@
65 return EmptyResultSet()
66 search_term = unicode(query)
67 store = IStore(SourcePackagePublishingHistory)
68- spns = store.using(
69+ dsps = store.using(
70 SourcePackagePublishingHistory,
71 LeftJoin(
72 SourcePackageRelease,
73@@ -2235,9 +2248,9 @@
74 SourcePackageRelease.sourcepackagenameID ==
75 SourcePackageName.id),
76 LeftJoin(
77- DistroSeries,
78- SourcePackagePublishingHistory.distroseriesID ==
79- DistroSeries.id),
80+ DistributionSourcePackageInDatabase,
81+ SourcePackageName.id ==
82+ DistributionSourcePackageInDatabase.sourcepackagename_id),
83 LeftJoin(
84 BinaryPackageBuild,
85 BinaryPackageBuild.source_package_release_id ==
86@@ -2250,8 +2263,9 @@
87 BinaryPackageRelease.binarypackagenameID ==
88 BinaryPackageName.id
89 )).find(
90- SourcePackageName,
91- DistroSeries.distributionID == distribution.id,
92+ DistributionSourcePackageInDatabase,
93+ DistributionSourcePackageInDatabase.distribution_id ==
94+ distribution.id,
95 SourcePackagePublishingHistory.status.is_in((
96 PackagePublishingStatus.PENDING,
97 PackagePublishingStatus.PUBLISHED)),
98@@ -2262,4 +2276,4 @@
99 BinaryPackageName.name.contains_string(
100 search_term))).config(distinct=True)
101 # XXX sinzui 2011-07-26: This query ignored SPN branches.
102- return CountableIterator(spns.count(), spns, self.toTerm)
103+ return CountableIterator(dsps.count(), dsps, self.toTerm)