python
data_error
ai_generated
true
django.db.utils.IntegrityError: UNIQUE constraint failed: auth_user.username
ID: python/django-user-creation-race
80%Fix Rate
85%Confidence
0Evidence
2024-11-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Two concurrent requests attempt to create a user with the same username.
generic中文
两个并发请求尝试创建具有相同用户名的用户。
Workarounds
-
90% success
Use transaction.atomic() and select_for_update to lock the row before checking existence.
Dead Ends
Common approaches that don't work:
-
60% fail
User isn't created, but no feedback given; data loss.
-
80% fail
Still can raise IntegrityError under concurrency.