修复scalar_one_or_none相关limit

This commit is contained in:
2026-06-03 14:15:21 +08:00
parent 446450c7d2
commit 8f27794da6
24 changed files with 73 additions and 52 deletions
+2 -2
View File
@@ -78,7 +78,7 @@ async def register(req: RegisterRequest, db: AsyncSession = Depends(get_db)):
)
# Check if phone already registered
existing = await db.execute(select(User).where(User.phone == req.phone))
existing = await db.execute(select(User).where(User.phone == req.phone).limit(1))
if existing.scalar_one_or_none():
from fastapi import HTTPException, status
raise HTTPException(
@@ -89,7 +89,7 @@ async def register(req: RegisterRequest, db: AsyncSession = Depends(get_db)):
# Create user with default username: 用户 + last 4 digits of phone
import random
username = f"用户{req.phone[-4:]}"
existing_name = await db.execute(select(User).where(User.username == username))
existing_name = await db.execute(select(User).where(User.username == username).limit(1))
if existing_name.scalar_one_or_none():
username = f"用户{req.phone[-4:]}{random.randint(10, 99)}"