Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 6677:8ab98de22df0
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 15 May 2022 12:02:57 -0400 |
| parents | 6f35be77324c |
| children | 8473039648da |
comparison
equal
deleted
inserted
replaced
| 6676:b336cc98d9d2 | 6677:8ab98de22df0 |
|---|---|
| 1569 """Build a tree of all transitive properties in the given | 1569 """Build a tree of all transitive properties in the given |
| 1570 exact_match_spec/filterspec. | 1570 exact_match_spec/filterspec. |
| 1571 If we retrieve (retr is True) linked items we don't follow | 1571 If we retrieve (retr is True) linked items we don't follow |
| 1572 across multilinks or links. | 1572 across multilinks or links. |
| 1573 """ | 1573 """ |
| 1574 if filterspec is None: | |
| 1575 filterspec = {} | |
| 1576 | |
| 1574 proptree = Proptree(self.db, self, '', self.getprops(), retr=retr) | 1577 proptree = Proptree(self.db, self, '', self.getprops(), retr=retr) |
| 1575 for exact, spec in enumerate((filterspec, exact_match_spec)): | 1578 for exact, spec in enumerate((filterspec, exact_match_spec)): |
| 1576 for key, v in spec.items(): | 1579 for key, v in spec.items(): |
| 1577 keys = key.split('.') | 1580 keys = key.split('.') |
| 1578 p = proptree | 1581 p = proptree |
| 1645 def _sortattr(self, sort=[], group=[]): | 1648 def _sortattr(self, sort=[], group=[]): |
| 1646 """Build a single list of sort attributes in the correct order | 1649 """Build a single list of sort attributes in the correct order |
| 1647 with sanity checks (no duplicate properties) included. Always | 1650 with sanity checks (no duplicate properties) included. Always |
| 1648 sort last by id -- if id is not already in sortattr. | 1651 sort last by id -- if id is not already in sortattr. |
| 1649 """ | 1652 """ |
| 1653 if sort is None: | |
| 1654 sort = [(None,None)] | |
| 1655 if group is None: | |
| 1656 group = [(None, None)] | |
| 1657 | |
| 1650 seen = {} | 1658 seen = {} |
| 1651 sortattr = [] | 1659 sortattr = [] |
| 1652 for srt in group, sort: | 1660 for srt in group, sort: |
| 1653 if not isinstance(srt, list): | 1661 if not isinstance(srt, list): |
| 1654 srt = [srt] | 1662 srt = [srt] |
| 1693 respectively. These can be used when displaying a number of | 1701 respectively. These can be used when displaying a number of |
| 1694 items in a pagination application or similar. A common use-case | 1702 items in a pagination application or similar. A common use-case |
| 1695 is returning the first item of a sorted search by specifying | 1703 is returning the first item of a sorted search by specifying |
| 1696 limit=1 (i.e. the maximum or minimum depending on sort order). | 1704 limit=1 (i.e. the maximum or minimum depending on sort order). |
| 1697 | 1705 |
| 1698 The filter must match all properties specificed. If the property | 1706 The filter must match all properties specified. If the property |
| 1699 value to match is a list: | 1707 value to match is a list: |
| 1700 | 1708 |
| 1701 1. String properties must match all elements in the list, and | 1709 1. String properties must match all elements in the list, and |
| 1702 2. Other properties must match any of the elements in the list. | 1710 2. Other properties must match any of the elements in the list. |
| 1703 | 1711 |
