-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre-validate uniqueness. #11
Comments
I'm interested in working on this! Which type of exception should be raised? A new Also, could you explain why the transaction is required? 😄 Can't it be enough to execute the various validation queries and then perform the insert? |
A
Let's not worry about that at the moment. But yeah, ideally you'd want that, otherwise there's a race condition between "We've checked uniqueness" and "we've performed the insert". If you get caught by that race, then you can end up having an DB error raised, rather than a nice validation error. |
I mean Django doesn't cover it I think, nor REST framework, so it's not really a big deal, and the integrity of the data is still safe, so it's really not a big deal in practice. |
Yes, I see. I also suppose we're safe since the data integrity is ensured by the database anyway (at least for MySQL and PostgreSQL). |
Eg. If
username
is a unique field, thenUser.objects.create(username=...)
should ideally:This is far more helpful than raising an integrity error.
The text was updated successfully, but these errors were encountered: