python
data_error
ai_generated
true
Django数据库完整性错误:唯一约束失败:auth_user.username
django.db.utils.IntegrityError: UNIQUE constraint failed: auth_user.username
ID: python/django-user-creation-race
80%修复率
85%置信度
0证据数
2024-11-03首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
两个并发请求尝试创建具有相同用户名的用户。
English
Two concurrent requests attempt to create a user with the same username.
解决方案
-
90% 成功率
Use transaction.atomic() and select_for_update to lock the row before checking existence.
无效尝试
常见但无效的做法:
-
60% 失败
User isn't created, but no feedback given; data loss.
-
80% 失败
Still can raise IntegrityError under concurrency.