Improve testability standards, and reliability for RegistrationForm.
Review Request #10838 — Created Jan. 19, 2020 and submitted
Djblets provides a
RegistrationFormfor helping register new users,
taking in a username, password, full name, and e-mail address. The code
for doing this is a bit old, wasn't unit tested, and had some warts.
There's improvements now in the documentation and coding style, bringing
it up to modern standards. The biggest changes, though, are in the
saving logic. We previously created the object in the parent database
transaction, and if there was a conflict, we'd try to fetch an existing
user to confirm and then provide an error to the user on the form.
The problem with this is that we'd break the transaction by way of
the constraint error, and then we'd try to look up the other user in the
same transaction. This didn't always work, and was a dangerous way of
doing it. Instead, we needed to ensure we were creating the object in
its own transaction, using
transaction.atomic(). This is the same
approach used by methods like
We also no longer fetch an entire
Userwhen checking for duplicates.
We just check if a row exists in the database. This speeds things up a
Unit tests have been added for all of
Unit tests pass on all supported versions of Django and Python.