[FIX] base: prevent traceback while invalid context pass

This issue occurs when a customer passes an invalid context in the view, at that
time this error will be generated.

Steps To Produce:-
- Go to `Settings >Technical >User Interface >Views`
- Open any view
- pass invalid context like
`context="{'search_default_demo': active_id}, 'search_default_x_stage_id':[3]}"`
-error will be generated

error-SyntaxError
unmatched '}' (<unknown>, line 1)

after this commit, we can display Validation Errors to users instead of a
traceback when they make mistakes in any UI view.

sentry-4684090820

closes odoo/odoo#145193

Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
sabr
2023-12-19 09:36:51 +00:00
parent 9b9e900dad
commit c2440fa562
2 changed files with 15 additions and 1 deletions
+10
View File
@@ -18161,6 +18161,16 @@ msgstr ""
msgid "Invalid composed field %(definition)s in %(use)s"
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/ir_ui_view.py:0
#, python-format
msgid ""
"Invalid context: %(expr)r is not a valid Python expression \n"
"\n"
" %(e)s"
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/ir_fields.py:0
+5 -1
View File
@@ -1646,7 +1646,11 @@ actual arch.
self._validate_classes(node, expr)
elif attr == 'context':
vnames = get_expression_field_names(expr) - {'id'}
try:
vnames = get_expression_field_names(expr) - {'id'}
except SyntaxError as e:
message = _('Invalid context: %(expr)r is not a valid Python expression \n\n %(e)s', expr=expr, e=e)
self._raise_view_error(message)
if vnames:
name_manager.must_have_fields(node, vnames, f"context ({expr})")
for key, val_ast in get_dict_asts(expr).items():