Skip to content

Commit 8b8b8bf

Browse files
committed
issue2551159 - cl.filter fails if filterspec is None ...
Fix case where passing None into a filter() call as the filterprop causes a traceback. Also fix cases where sort or group are None causing tracebacks. Also fix typo in hyperdb filter() docstring.
1 parent ba37ea7 commit 8b8b8bf

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

roundup/hyperdb.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,9 @@ def _proptree(self, filterspec, exact_match_spec={}, sortattr=[],
15711571
If we retrieve (retr is True) linked items we don't follow
15721572
across multilinks or links.
15731573
"""
1574+
if filterspec is None:
1575+
filterspec = {}
1576+
15741577
proptree = Proptree(self.db, self, '', self.getprops(), retr=retr)
15751578
for exact, spec in enumerate((filterspec, exact_match_spec)):
15761579
for key, v in spec.items():
@@ -1647,6 +1650,11 @@ def _sortattr(self, sort=[], group=[]):
16471650
with sanity checks (no duplicate properties) included. Always
16481651
sort last by id -- if id is not already in sortattr.
16491652
"""
1653+
if sort is None:
1654+
sort = [(None,None)]
1655+
if group is None:
1656+
group = [(None, None)]
1657+
16501658
seen = {}
16511659
sortattr = []
16521660
for srt in group, sort:
@@ -1695,7 +1703,7 @@ def filter(self, search_matches, filterspec, sort=[], group=[],
16951703
is returning the first item of a sorted search by specifying
16961704
limit=1 (i.e. the maximum or minimum depending on sort order).
16971705
1698-
The filter must match all properties specificed. If the property
1706+
The filter must match all properties specified. If the property
16991707
value to match is a list:
17001708
17011709
1. String properties must match all elements in the list, and

test/db_test_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,23 @@ def filteringSetup(self, classname='issue'):
18071807
self.db.commit()
18081808
return self.iterSetup(classname)
18091809

1810+
def testFilteringNone(self):
1811+
ae, iiter = self.filteringSetup()
1812+
for filt in iiter():
1813+
ae(filt(None, None, ('+','id'), (None,None)), ['1', '2', '3', '4'])
1814+
1815+
def testSortingNone(self):
1816+
ae, iiter = self.filteringSetup()
1817+
for filt in iiter():
1818+
ae(filt(None, {'id': ['1','3','4']}, None, ('-', 'status')),
1819+
['3', '4', '1'])
1820+
1821+
def testGroupingNone(self):
1822+
ae, iiter = self.filteringSetup()
1823+
for filt in iiter():
1824+
ae(filt(None, {'title': ['issue']}, [('-', 'id')],
1825+
None), ['3', '2', '1'])
1826+
18101827
def testFilteringID(self):
18111828
ae, iiter = self.filteringSetup()
18121829
for filt in iiter():

0 commit comments

Comments
 (0)