fix: raise better error if field widget serialization fails
and log a warning with traceback while we're at it
This commit is contained in:
parent
faae9f1b0a
commit
485c503212
2 changed files with 20 additions and 1 deletions
|
|
@ -1138,7 +1138,18 @@ class Form: # pylint: disable=too-many-instance-attributes,too-many-public-meth
|
|||
field = dform[fieldname]
|
||||
if readonly:
|
||||
kwargs["readonly"] = True
|
||||
html = field.serialize(**kwargs)
|
||||
|
||||
try:
|
||||
html = field.serialize(**kwargs)
|
||||
except Exception as exc:
|
||||
log.warning(
|
||||
"widget serialization failed for field: %s",
|
||||
fieldname,
|
||||
exc_info=True,
|
||||
)
|
||||
raise RuntimeError(
|
||||
f"widget serialization failed for field: {fieldname}"
|
||||
) from exc
|
||||
|
||||
else:
|
||||
# render static text if field not in deform/schema
|
||||
|
|
|
|||
|
|
@ -587,6 +587,14 @@ class TestForm(WebTestCase):
|
|||
html = form.render_vue_field("foo")
|
||||
self.assertIn("something is wrong", html)
|
||||
|
||||
class BadWidget(deform.widget.Widget):
|
||||
def serialize(self, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
# widget serialization error
|
||||
dform["foo"].widget = BadWidget()
|
||||
self.assertRaises(RuntimeError, form.render_vue_field, "foo")
|
||||
|
||||
# add another field, but not to deform, so it should still
|
||||
# display but with no widget
|
||||
form.fields.append("zanzibar")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue