django - Avoiding race condition between validation for uniqueness and insertion -


i have django 1.7 beta 1 project standard user signup form.

conceptually, makes sense form validation fail if username taken. however, form validation , saving of created user model separate steps, there's race condition validation can pass actual user.save() can fail integrityerror.

i'm unclear on happens if both form validation , user.save() step wrapped in same transaction.atomic() block -- assumption postgres not create locks when table read check if row exists, , therefore transaction not prevent race condition @ all.

assuming that's case, best way handle this? here options i'm considering far:

  • skip username uniqueness validation entirely , catch integrityerror on save time, adding form errors list manually. bulletproof, moves validation logic outside of form definition.
  • do both validation step , try/except block around integrityerror. may add duplicate code, form works in isolation , use of form in view doesn't cause race condition.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -