Skip to content

Commit ddfb243

Browse files
committed
doc/test: issue2551374 - add error handling for filter expressions
Added doc that invalid filter expressions are silently ignored and a fallback search is generated. Added disabled test that uses incorrect filter expression examples from this issue.
1 parent 2a44328 commit ddfb243

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

doc/user_guide.txt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,48 +449,54 @@ Advanced Searching with Property Expressions
449449
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450450

451451
You can create more advanced searches in your tracker by using Reverse
452-
Polish Notation (`RPN`_) to make property expressions. By default, when
453-
filtering by multiple items, the expression type is 'or'. For
452+
Polish Notation (`RPN`_) to make property expressions. By default,
453+
when filtering by multiple items, the expression type is 'or'. For
454454
instance, if you filter the property assignedto by adding the query
455-
string element "assignedto=2,3,40", it matches users "2 or 3 or
456-
40". In RPN, this would be written as "2, 3, or, 4, or". Roundup uses
457-
negative numbers to represent operators. For example, using "-1" for a
458-
single value (e.g. the assignedto Link property, but not the keyword
459-
multivalued/MultiLink property) matches an issue where the property is
460-
'not set'.
455+
string element ``assignedto=2,3,40``, it matches users numbered ``2 or
456+
3 or 40``. In RPN, this would be written as ``2, 3, or, 4,
457+
or``. Roundup uses negative numbers to represent operators. For
458+
example, using "-1" for a single value (e.g. the assignedto Link
459+
property, but not the keyword multivalued/MultiLink property) matches
460+
an issue where the property is 'not set'.
461461

462462
The operators and their corresponding numbers are:
463463

464464
* 'not' is represented by -2
465465
* 'and' is represented by -3
466466
* 'or' is represented by -4
467467

468-
So, "assignedto=2,3,40" is the same as
469-
"assignedto=2,3,-4,40,-4". While this example is the same as
470-
"2,3,40", the expression "keyword=1,2,-3,-2" filters issues that don't
471-
have both keywords 1 and 2.
468+
So, ``assignedto=2,3,40`` is the same as
469+
``assignedto=2,3,-4,40,-4``. While this example is the same as
470+
``2,3,40``, the expression ``keyword=1,2,-3,-2`` filters issues that
471+
don't have both keywords 1 and 2.
472472

473473
Another example is: ``creator=3,-2,1,-2,-3``. This is the same as the
474474
expression: ``(not user3) and (not user1)``. Using the rules of logic,
475475
this is the same as: ``not (user3 or user1)`` which is expressed in
476476
RPN as ``creator=3,1,-4,-2``. Compare this to ``creator=3,1,-2`` which
477477
returns issues created by user3 or any user other than user1.
478478

479-
Another example, useful when filtering issues, is:
479+
Another example, useful when filtering issues, is::
480480

481481
keyword=-1,-2,1,8,-3,-2,-3
482482

483483
which returns issues that have one or more keywords set and the issue
484484
does not have keyword1 and keyword8 both set. In more standard infix
485-
form:
485+
form::
486486

487487
not empty and not (keyword1 and keyword8)
488488

489-
Typing these expressions manually can be tiresome, so there's an
490-
expression editor on the search page. You can access it by clicking on
491-
the ``(expr)`` link, which makes creating these expressions a bit
492-
easier. But at least you can use this info to understand the search
493-
syntax in the URL.
489+
Typing these expressions manually can be tiresome and tricky. On the
490+
search page, there's an expression editor. You can access it by
491+
clicking on the ``(expr)`` link, which makes creating these
492+
expressions a bit easier.
493+
494+
Note that errors in your expression (e.g. a missing operand) are
495+
silently ignored and a fallback search is conducted. This is
496+
`considered a bug <https://issues.roundup-tracker.org/issue2551374>`_
497+
and will hopefully be fixed in the future. But at least you can use
498+
this info to understand the search syntax in the URL if you see
499+
something strange.
494500

495501
Using the Classhelper
496502
---------------------

test/db_test_base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,25 @@ def testFilteringLinkExpression(self):
20742074
ae(filt(None, {a: ['1','-2','2','-2','-4']}, ('+',a)),
20752075
['3','4','1','2'])
20762076

2077+
def NOtestFilteringLinkInvalid(self):
2078+
"""Test invalid filter expressions.
2079+
Code must be written to generate an exception for these.
2080+
Then this code must be changed to test the exception.
2081+
See issue 2551374 in the roundup tracker.
2082+
"""
2083+
ae, iiter = self.filteringSetup()
2084+
a = 'assignedto'
2085+
# filt(??, filter expression, sort order)
2086+
# ae = self.assertEqual(val1, val2)
2087+
for filt in iiter():
2088+
# -2 is missing an operand
2089+
ae(filt(None, {a: ['-2','2','-2','-4']},
2090+
('+',a)), [])
2091+
# 3 is left on the stack
2092+
ae(filt(None, {a: ['3','2','-2']},
2093+
('+',a)), [])
2094+
2095+
20772096
def testFilteringRevLink(self):
20782097
ae, iiter = self.filteringSetupTransitiveSearch('user')
20792098
# We have

0 commit comments

Comments
 (0)