misc: add proper reporting for invalid get parameter (#77716) #864
|
@ -429,6 +429,11 @@ def test_inspect_page(pub, local_user):
|
|||
assert resp.pyquery('#test-tool-result p:last-child').text() == 'Invalid filter "not a field"'
|
||||
assert pub.loggederror_class.count() == 0
|
||||
|
||||
resp.form['django-condition'] = 'form_objects|first|get:0'
|
||||
resp = resp.form.submit()
|
||||
assert resp.pyquery('#test-tool-result p:last-child').text() == '|get called with invalid key (0)'
|
||||
assert pub.loggederror_class.count() == 0
|
||||
|
||||
# check there's a custom hint when a template is used as condition
|
||||
resp.form['test_mode'] = 'django-condition'
|
||||
resp.form['django-condition'] = '{% if True %}hello{% endif %}'
|
||||
|
|
|
@ -1889,6 +1889,17 @@ def test_lazy_formdata_queryset_get_from_first(pub, variable_test_data):
|
|||
assert tmpl.render(context) == 'bar'
|
||||
|
||||
|
||||
def test_lazy_formdata_get_error_report(pub, variable_test_data):
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
del context['form'] # remove actual form from context
|
||||
pub.loggederror_class.wipe()
|
||||
tmpl = Template('{{forms|objects:"foobarlazy"|first|get:0}}')
|
||||
assert tmpl.render(context) == 'None'
|
||||
assert pub.loggederror_class.count() == 1
|
||||
logged_error = pub.loggederror_class.select()[0]
|
||||
assert logged_error.summary == '|get called with invalid key (0)'
|
||||
|
||||
|
||||
def test_lazy_formdata_queryset_order_by(pub, variable_test_data):
|
||||
lazy_formdata = variable_test_data
|
||||
data_class = lazy_formdata._formdef.data_class()
|
||||
|
|
|
@ -1033,6 +1033,9 @@ class LazyFormData(LazyFormDef):
|
|||
# queryset|first|get:"form_var_plop"
|
||||
compat_dict = CompatibilityNamesDict({'form': self})
|
||||
return compat_dict.get(key)
|
||||
except Exception as e:
|
||||
get_publisher().record_error(_('|get called with invalid key (%s)') % key, exception=e)
|
||||
return None
|
||||
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue