ValueError raised getting length of batch results

Bug #683115 reported by Diogo Matsubara
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
High
Gary Poster

Bug Description

As seen on OOPS-1794M1115 a ValueError: __len__() should return >= 0 was raised getting the length of a batch result.

This might be a bug on lazr.batchnavigator.

Related branches

Revision history for this message
Gary Poster (gary) wrote :

I dug into this a bit. I do not believe that this is a bug in lazr.batchnavigator, or at least not in lazr.batchnavigator.z3batching.batch. The error comes when the len *of the underlying result object* (not the batch itself) is less than zero.

The OOPS is for the search page (lp.app.browser.root.LaunchpadSearchView), when rendering the expression view/pages/@@+navigation-links-upper.

"view/pages" in this case is a GoogleBatchNavigator. It's created in this code:

        if len(page_matches) == 0:
            return None
        navigator = GoogleBatchNavigator(
            page_matches, self.request, start=start)

The page_matches in that code is the underlying result object. It is defined in lib/canonical/launchpad/utilities/searchservice.py . The value that is a negative number appears to be "total = int(results.find('M').text)" in that file. I'd like to test if it is less than zero, and, if so, either raise an error there, or create an informational oops and set total to zero.

Changed in launchpad-foundations:
status: New → Triaged
importance: Undecided → Medium
Gary Poster (gary)
Changed in launchpad-foundations:
importance: Medium → High
Gary Poster (gary)
Changed in launchpad-foundations:
assignee: nobody → Gary Poster (gary)
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Isn't the "negative" number simply the None? After all, in python, None < 0.

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 683115] Re: ValueError raised getting length of batch results

On Wed, Dec 1, 2010 at 8:35 PM, Jeroen T. Vermeulen
<email address hidden> wrote:
> Isn't the "negative" number simply the None?  After all, in python, None
> < 0.

nit: in Python 2, None is < everything. In Python 3 that expression
will raise a TypeError:

>>> None < 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()

Revision history for this message
Gary Poster (gary) wrote :

@jtv: I don't think so. As noted in the original bug report, we are getting a ValueError. if __len__ returns None, that generates a TypeError, even in 2.6.

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def __len__(self): return None
...
>>> foo = Foo()
>>> len(foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

Revision history for this message
Launchpad QA Bot (lpqabot) wrote : Bug fixed by a commit
Changed in launchpad-foundations:
milestone: none → 10.12
tags: added: qa-needstesting
Changed in launchpad-foundations:
status: Triaged → Fix Committed
Gary Poster (gary)
tags: added: qa-untestable
removed: qa-needstesting
Changed in launchpad-foundations:
status: Fix Committed → Triaged
assignee: Gary Poster (gary) → nobody
Revision history for this message
Gary Poster (gary) wrote :

It looks like my diagnosis was right. There are not instances of the original OOPS since the deployment. However, the OOPS report does include this error, raised from code in my branch:

  1 GoogleResponseError: The reported total (-1, from '-1') was less than zero. See bug 683115.
   GET: 1 Robots: 0 Local: 1
      1 https://launchpad.net/+search (RootObject:+search)
       OOPS-1807O1888

We've had four in the last four days since this change was rolled out.

Therefore, to fix the root cause of the error, we would need to look into why the Google XML response was giving us a "total results" count of -1. To paste over the error, in Launchpad code we can convert the -1 (or anything lower than 0) to 0.

Looking into the first approach, the "total" is the "M" value in the Google response (http://code.google.com/apis/searchappliance/documentation/68/xml_reference.html#results_xml_tag_m). This is an approximation. Curtis, who coded our Google integration, reports that "Google does not guarantee the number in the index matches the number in the cache. -1 can happen when they are out of sync". He also confirms that we can treat -1 as 0. I will make this change, removing the custom exception I raised, and then close this bug.

Changed in launchpad-foundations:
assignee: nobody → Gary Poster (gary)
Gary Poster (gary)
Changed in launchpad-foundations:
status: Triaged → In Progress
Revision history for this message
Launchpad QA Bot (lpqabot) wrote :
Changed in launchpad-foundations:
milestone: 10.12 → none
tags: added: qa-needstesting
removed: qa-untestable
Changed in launchpad-foundations:
status: In Progress → Fix Committed
Gary Poster (gary)
tags: added: qa-untestable
removed: qa-needstesting
Curtis Hovey (sinzui)
Changed in launchpad:
status: Fix Committed → Fix Released
Curtis Hovey (sinzui)
Changed in launchpad:
milestone: none → 11.01
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.