Merge lp:~bac/launchpad/voucherdot into lp:launchpad

Proposed by Brad Crittenden
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bac/launchpad/voucherdot
Merge into: lp:launchpad
Diff against target: 35 lines (+12/-2)
2 files modified
lib/lp/registry/doc/commercialsubscription.txt (+8/-0)
lib/lp/registry/model/product.py (+4/-2)
To merge this branch: bzr merge lp:~bac/launchpad/voucherdot
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+22754@code.launchpad.net

Commit message

Allow ProductSet.forReview() to find product's with special characters in the name.

Description of the change

= Summary =

When trying to assign a voucher to a product with a (legal) dot in it's
name there was an InvalidValue error because the vocabulary invoked
during widget validation returned no product. The vocabulary uses
ProductSet.forReview() to look up the product, which only uses an fti
search.

== Proposed fix ==

Comparing with the PillarSet.search() shows that the latter has an extra
clause to match on the pillar name. Such a clause has been added to the
forReview search.

== Pre-implementation notes ==

None

== Implementation details ==

As above.

== Tests ==

bin/text -vvm lp.registry -t commercialsubscription.txt

== Demo and Q/A ==

Attempt to assign a voucher to the accountz.com outstanding project.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/registry/doc/commercialsubscription.txt
  lib/lp/registry/model/product.py

== Pylint notices ==

lib/lp/registry/model/product.py
    22: [F0401] Unable to import 'zope.interface'
    23: [F0401] Unable to import 'zope.component'
    24: [F0401] Unable to import 'zope.security.proxy'
    27: [F0401] Unable to import 'lazr.delegates'

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

Oh. I think I discovered this last year while searching. Thanks for the fix.

review: Approve (code)
Revision history for this message
Brad Crittenden (bac) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/doc/commercialsubscription.txt'
2--- lib/lp/registry/doc/commercialsubscription.txt 2010-02-17 11:19:42 +0000
3+++ lib/lp/registry/doc/commercialsubscription.txt 2010-04-03 21:16:25 +0000
4@@ -518,6 +518,14 @@
5 ...
6 AssertionError...
7
8+The full text search will not match strings with dots in their name
9+but a clause is included to search specifically for the name.
10+
11+ >>> new_product = factory.makeProduct(name="abc.com")
12+ >>> for product in product_set.forReview(search_text="abc.com"):
13+ ... print product.name
14+ abc.com
15+
16 The use of 'forReview' is limited to users with launchpad.Commercial permission.
17
18 Anonymous users cannot access 'forReview'.
19
20=== modified file 'lib/lp/registry/model/product.py'
21--- lib/lp/registry/model/product.py 2010-03-19 11:13:00 +0000
22+++ lib/lp/registry/model/product.py 2010-04-03 21:16:25 +0000
23@@ -1141,8 +1141,10 @@
24 conditions.append(Product.active == active)
25
26 if search_text is not None and search_text.strip() != '':
27- conditions.append(SQL(
28- 'Product.fti @@ ftq(%s)' % sqlvalues(search_text)))
29+ conditions.append(SQL('''
30+ Product.fti @@ ftq(%(text)s) OR
31+ Product.name = lower(%(text)s)
32+ ''' % sqlvalues(text=search_text)))
33
34 def dateToDatetime(date):
35 """Convert a datetime.date to a datetime.datetime