Merge pull request #2699 from yueguobin/fix/template-duplicate-name-validation

Fix duplicate template name validation when updating templates
This commit is contained in:
Jeremy Grossmann 2026-05-03 12:09:59 +08:00 committed by GitHub
commit c45f6d9416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -281,6 +281,14 @@ class TemplatesService:
if not db_template:
raise ControllerNotFoundError(f"Template '{template_id}' not found")
# Check for duplicate name (excluding current template)
if template_update.name is not None:
existing_template = await self._templates_repo.get_template_by_name_and_version(
template_update.name, db_template.version
)
if existing_template and existing_template.template_id != template_id:
raise ControllerError(f"A template with name '{template_update.name}' already exists")
try:
# validate the update settings
update_settings = jsonable_encoder(template_update, exclude_unset=True)