修复scalar_one_or_none相关limit
This commit is contained in:
@@ -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)}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user