From 1d715e146b9fdd40218b2fb7e409b758e728ecdd Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Sun, 3 May 2026 11:06:02 +0800 Subject: [PATCH] fix: add duplicate name validation when updating templates Fixes #1658 Add validation in the update_template method to check if a template with the same name already exists before updating. This prevents users from creating duplicate template names by editing existing templates. The check excludes the current template being edited to allow updating other properties without changing the name. --- gns3server/services/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gns3server/services/templates.py b/gns3server/services/templates.py index d2856c0d8..92b78633e 100644 --- a/gns3server/services/templates.py +++ b/gns3server/services/templates.py @@ -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)