Refa: create new name for duplicated dialog name (#9558)

### What problem does this PR solve?

 Create new name for duplicated dialog name.

### Type of change

- [x] Refactoring
This commit is contained in:
Yongteng Lei
2025-08-19 18:14:04 +08:00
committed by GitHub
parent b8bfbac2e5
commit 33f3e05b75

View File

@ -16,6 +16,7 @@
from flask import request
from flask_login import login_required, current_user
from api.db.services import duplicate_name
from api.db.services.dialog_service import DialogService
from api.db import StatusEnum
from api.db.services.tenant_llm_service import TenantLLMService
@ -42,8 +43,14 @@ def set_dialog():
if len(name.encode("utf-8")) > 255:
return get_data_error_result(message=f"Dialog name length is {len(name)} which is larger than 255")
if DialogService.get_or_none(tenant_id=current_user.id, name=name):
return get_data_error_result(message=f"Duplicated Dialog name {name}.")
if is_create and DialogService.query(tenant_id=current_user.id, name=name.strip()):
name = name.strip()
name = duplicate_name(
DialogService.query,
name=name,
tenant_id=current_user.id,
status=StatusEnum.VALID.value)
description = req.get("description", "A helpful dialog")
icon = req.get("icon", "")
top_n = req.get("top_n", 6)