Fix problems with invalid OAuth application form and ListEditField

Review Request #12468 — Created July 13, 2022 and submitted

Information

Djblets
release-3.x

Reviewers

A validation error can occur when submitting the OAuth app form (such as when
redirect URIs are invalid URLs). When these validation errors occur, it messes
up the flow between ListEditField and ListEditWidget (which are the field and
widget for the redirect URIs field) and causing a value error.

On a normal basis, when submitting the form, the
ListEditWidget.value_from_datadict method is called, which extracts the
redirect URIs data from the form and returns a list of redirect URIs. Then this
list is passed to ListEditField.to_python, which takes the list and transforms
it into a string of comma separated redirect URIs, and this gets stored in the
database. When the page reloads after the form is submitted,
ListEditField.prepare_value is called to take the string from the database and
turn it into a list to pass to the widget for when it renders. This is good.

When a validation error occurs, the list is never passed to
ListEditField.to_python because we're not storing in the database since
there's an error. So instead when the page reloads, the list from
ListEditWidget.value_from_datadict is passed to
ListEditField.prepare_value, which only accepts strings or None, and this
is why we're getting the value error.

To fix this, we allow ListEditField.prepare_value to handle lists. We make
this change to ListEditDictionaryField.prepare_value as well, so that it
can also handle cases where a form that contains the field errors out.

  • Ran tests in djblets/forms/tests
  • Ran tests in /reviewboard/webapi/tests/testauth_app.py
  • Ran tests in ./reviewboard/admin/tests/test_lexers_mapping_widget.py
  • Manually tested the OAuth Application form with combinations of valid and
    invalid redirect URIs and blank URIs
Summary ID
Fix problems with invalid OAuth application form and ListEditField
bb1275eec795b5b8f527245ffdb2be5d40b6d7d1
chipx86
  1. Ship It!
  2. 
      
maubin
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.x (34bbda2)