Homec4science

Fix transaction handling in PhabricatorUserEditor->createNewUser()

Authored by epriestley <git@epriestley.com> on Jun 5 2012, 15:46.

Description

Fix transaction handling in PhabricatorUserEditor->createNewUser()

Summary:
See https://github.com/facebook/phabricator/issues/117

  • The $user save can hit a duplicate key exception like the email, but we don't handle it correctly.
  • When the $user saves but the $email does not, the $user is left with a (rolled-back, invalid) ID. This makes the UI glitch out a bit. Wipe the ID if we abort the transaction.
  • We show the "Required" star marker even if the email is filled in.

The ID issue is sort of a general problem, but I think it's fairly rare: you must be doing inserts on related objects and the caller must catch the transaction failure and attempt to handle it in some way.

I can think of three approaches:

  • Manually "roll back" the objects inside the transaction, as here. Seems OK if this really is a rare problem.
  • Automatically roll back the 'id' and 'phid' columns (if they exist). Seems reasonable but maybe more complicated than necessary. Won't get every case right. For instance, if we inserted a third object here and that failed, $email would still have the userPHID set.
  • Automatically roll back the entire object. We can do this by cloning all the writable fields. Seems like it might be way too magical, but maybe the right solution? Might have weird bugs with nonwritable fields and other random stuff.

We can trigger the rollback by storing objects we updated on the transaction, and either throwing them away or rolling them back on saveTransaction() / killTransaction().

These fancier approaches all seem to have some tradeoffs though, and I don't think we need to pick one yet, since this has only caused problems in one case.

Test Plan: Tried to create a new user (via People -> Create New User) with a duplicate username. Got a proper UI message with no exception and no UI glitchiness.

Reviewers: btrahan, vrana, hgrimberg, hgrimberg01

Reviewed By: hgrimberg01

CC: aran

Differential Revision: https://secure.phabricator.com/D2650

Details

Committed
epriestley <git@epriestley.com>Jun 5 2012, 15:46
Pushed
aubortJan 31 2017, 17:16
Parents
rPHc0c54e861e5f: Merge pull request #122 from KorvinSzanto/master
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPH489303a0572a: Fix transaction handling in PhabricatorUserEditor->createNewUser() (authored by epriestley <git@epriestley.com>).Jun 5 2012, 15:46