Skip to content

Commit 5e42b71

Browse files
committed
Fix traceback if an order attribute is None
Fixes issue2551207.
1 parent 5fd1b1b commit 5e42b71

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Fixed:
9797
- new option added to config.ini: login_empty_passwords set to
9898
no by default. Setting this to yes allows a user with an
9999
empty password to login.
100+
- issue2551207 - Fix sorting by order attribute if order attributes can
101+
be None. Add a test.
100102

101103
Features:
102104

roundup/cgi/templating.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,9 @@ def make_key_function(db, classname, sort_on=None):
28832883
def keyfunc(a):
28842884
if num_re.match(a):
28852885
a = linkcl.get(a, sort_on)
2886+
# In Python3 we may not compare strings and None
2887+
if a is None :
2888+
return ''
28862889
return a
28872890
return keyfunc
28882891

test/test_templating.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ def test_HTMLDatabase_classes(self):
108108
db._db.classes = {'issue':MockNull(), 'user': MockNull()}
109109
db.classes()
110110

111+
def test_HTMLDatabase_list(self):
112+
# The list method used to produce a traceback when a None value
113+
# for an order attribute of a class was encountered. This
114+
# happens when the 'get' of the order attribute for a numeric
115+
# id produced a None value. So we put '23' as a key into the
116+
# list and set things up that a None value is returned on 'get'.
117+
118+
# This keeps db.issue static, otherwise it changes for each call
119+
db = MockNull(issue = HTMLDatabase(self.client).issue)
120+
db.issue._klass.list = lambda : ['23', 'a', 'b']
121+
# Make db.getclass return something that has a sensible 'get' method
122+
mock = MockNull(get = lambda x, y : None)
123+
db.issue._db.getclass = lambda x : mock
124+
l = db.issue.list()
125+
111126
class FunctionsTestCase(TemplatingTestCase):
112127
def test_lookupIds(self):
113128
db = HTMLDatabase(self.client)

0 commit comments

Comments
 (0)