comparison roundup/backends/back_anydbm.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 9056b0c8fcd6
children 24549122f9b1
comparison
equal deleted inserted replaced
8240:1189c742e4b3 8241:741ea8a86012
32 32
33 from roundup.anypy.dbm_ import anydbm, whichdb 33 from roundup.anypy.dbm_ import anydbm, whichdb
34 from roundup.anypy.strings import b2s, bs2b, repr_export, eval_import, is_us 34 from roundup.anypy.strings import b2s, bs2b, repr_export, eval_import, is_us
35 35
36 from roundup import hyperdb, date, password, roundupdb, security, support 36 from roundup import hyperdb, date, password, roundupdb, security, support
37 from roundup.mlink_expr import Expression 37 from roundup.mlink_expr import Expression, ExpressionError
38 from roundup.backends import locking 38 from roundup.backends import locking
39 from roundup.i18n import _ 39 from roundup.i18n import _
40 40
41 from roundup.backends.blobfiles import FileStorage 41 from roundup.backends.blobfiles import FileStorage
42 from roundup.backends import sessions_dbm 42 from roundup.backends import sessions_dbm
1878 1878
1879 # now apply the property filter 1879 # now apply the property filter
1880 if t == LINK: 1880 if t == LINK:
1881 # link - if this node's property doesn't appear in the 1881 # link - if this node's property doesn't appear in the
1882 # filterspec's nodeid list, skip it 1882 # filterspec's nodeid list, skip it
1883 expr = Expression(v, is_link=True) 1883 try:
1884 expr = Expression(v, is_link=True)
1885 except ExpressionError as e:
1886 e.context['class'] = cn
1887 e.context['attr'] = k
1888 raise
1884 if expr.evaluate(nv): 1889 if expr.evaluate(nv):
1885 match = 1 1890 match = 1
1886 elif t == MULTILINK: 1891 elif t == MULTILINK:
1887 # multilink - if any of the nodeids required by the 1892 # multilink - if any of the nodeids required by the
1888 # filterspec aren't in this node's property, then skip 1893 # filterspec aren't in this node's property, then skip
1893 if not v: 1898 if not v:
1894 match = not nv 1899 match = not nv
1895 else: 1900 else:
1896 # otherwise, make sure this node has each of the 1901 # otherwise, make sure this node has each of the
1897 # required values 1902 # required values
1898 expr = Expression(v) 1903 try:
1904 expr = Expression(v)
1905 except ExpressionError as e:
1906 e.context['class'] = cn
1907 e.context['attr'] = k
1908 raise
1899 if expr.evaluate(nv): 1909 if expr.evaluate(nv):
1900 match = 1 1910 match = 1
1901 elif t == STRING: 1911 elif t == STRING:
1902 if nv is None: 1912 if nv is None:
1903 nv = '' 1913 nv = ''

Roundup Issue Tracker: http://roundup-tracker.org/