• 
      

    Bug # sorting TypeError fix

    Review Request #1168 — Created Oct. 8, 2009 and submitted

    Information

    Review Board

    Reviewers

    When entering multiple long numbers in the bug list of a review request, posting the request resulted in a TypeError. This patch should correct the issue.
    Tested with a local Review Board installation. Numerical and lexicographical sorting still work correctly after applying the fix. Large bug # no longer trigger a TypeError.
    chipx86
    1. Thanks. Committed along with a unit test to master as r10b5857.
    2. 
        
    VL
    1. I do not like the implementation:
      
      >>> bugs=['123456789123456789','89']
      >>> bugs.sort(cmp=lambda x,y: int(x) - int(y))
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: comparison function must return int, not long
      
      The proper way is to use python's function "cmp":
      >>> bugs=['123456789123456789','89']
      >>> bugs.sort(lambda x,y: cmp(int(x),int(y)))
      >>> bugs
      ['89', '123456789123456789']
    2. reviewboard/reviews/models.py (Diff revision 1)
       
       
      Very dodgy hack.
      
      This would not handle the case when the difference between x and y is a long number.
      
      The correct way is as follows:
      bugs.sort(lambda x,y: cmp(int(x),int(y)))
      1. Yeah, you're right. Fixed and updated the unit test to better check comparisons of longs with long results.
    3.