Mercurial > p > roundup > code
comparison roundup/backends/rdbms_common.py @ 8241:741ea8a86012
fix: issue2551374. Error handling for filter expressions.
Errors in filter expressions are now reported. The UI needs some work
but even the current code is helpful when debugging filter
expressions.
mlink_expr:
defines/raises ExpressionError(error string template,
context=dict())
raises ExpressionError when it detects errors when popping arguments
off stack
raises ExpressionError when more than one element left on the stack
before returning
also ruff fix to group boolean expression with parens
back_anydbm.py, rdbms_common.py:
catches ExpressionError, augments context with class and
attribute being searched. raises the exception
for both link and multilink relations
client.py
catches ExpressionError returning a basic error page. The page is a
dead end. There are no links or anything for the user to move
forward. The user has to go back, possibly refresh the page (because
the submit button may be disalbled) re-enter the query and try
again.
This needs to be improved.
test_liveserver.py
test the error page generated by client.py
db_test_base
unit tests for filter with too few arguments, too many arguments,
check all repr and str formats.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 30 Dec 2024 20:22:55 -0500 |
| parents | a9b136565838 |
| children | 82a26ea1afdf |
comparison
equal
deleted
inserted
replaced
| 8240:1189c742e4b3 | 8241:741ea8a86012 |
|---|---|
| 70 from roundup.backends.sessions_rdbms import Sessions, OneTimeKeys | 70 from roundup.backends.sessions_rdbms import Sessions, OneTimeKeys |
| 71 from roundup.date import Range | 71 from roundup.date import Range |
| 72 from roundup.hyperdb import String, Password, Date, Interval, Link, \ | 72 from roundup.hyperdb import String, Password, Date, Interval, Link, \ |
| 73 Multilink, DatabaseError, Boolean, Number, Integer | 73 Multilink, DatabaseError, Boolean, Number, Integer |
| 74 from roundup.i18n import _ | 74 from roundup.i18n import _ |
| 75 from roundup.mlink_expr import compile_expression | 75 from roundup.mlink_expr import compile_expression, ExpressionError |
| 76 | 76 |
| 77 # dummy value meaning "argument not passed" | 77 # dummy value meaning "argument not passed" |
| 78 _marker = [] | 78 _marker = [] |
| 79 | 79 |
| 80 # python 3 doesn't have a unicode type | 80 # python 3 doesn't have a unicode type |
| 2592 def collect_values(n): | 2592 def collect_values(n): |
| 2593 if n.x >= 0: | 2593 if n.x >= 0: |
| 2594 values.append(n.x) | 2594 values.append(n.x) |
| 2595 expr.visit(collect_values) | 2595 expr.visit(collect_values) |
| 2596 return w, values | 2596 return w, values |
| 2597 except ExpressionError as e: | |
| 2598 e.context['class'] = pln | |
| 2599 e.context['attr'] = prp | |
| 2600 raise | |
| 2597 except: | 2601 except: |
| 2598 pass | 2602 pass |
| 2599 # Fallback to original code | 2603 # Fallback to original code |
| 2600 args = [] | 2604 args = [] |
| 2601 where = None | 2605 where = None |
| 2669 if n.x >= 0: | 2673 if n.x >= 0: |
| 2670 values.append(n.x) | 2674 values.append(n.x) |
| 2671 expr.visit(collect_values) | 2675 expr.visit(collect_values) |
| 2672 | 2676 |
| 2673 return intron, values | 2677 return intron, values |
| 2678 except ExpressionError as e: | |
| 2679 e.context['class'] = classname | |
| 2680 e.context['attr'] = proptree.name | |
| 2681 raise | |
| 2674 except: | 2682 except: |
| 2675 # fallback behavior when expression parsing above fails | 2683 # fallback behavior when expression parsing above fails |
| 2676 orclause = '' | 2684 orclause = '' |
| 2677 if '-1' in v: | 2685 if '-1' in v: |
| 2678 v = [x for x in v if int(x) > 0] | 2686 v = [x for x in v if int(x) > 0] |
