feat(templates): safely access settings dict keys

Use dict.get() method to safely access 'image' and 'path' keys in settings dictionary to avoid KeyError exceptions when these keys are missing. This improves error handling and prevents server crashes when creating templates with incomplete settings.
This commit is contained in:
YueGuobin 2026-02-23 01:02:32 +08:00
parent e27ddf2cdf
commit c05f667f3d

View File

@ -197,7 +197,7 @@ class TemplatesService:
images_to_add_to_template = []
if template_type == "dynamips":
if settings["image"]:
if settings.get("image"):
image = await self._find_image(settings["image"])
if image.image_type != "ios":
raise ControllerBadRequestError(
@ -205,7 +205,7 @@ class TemplatesService:
)
images_to_add_to_template.append(image)
elif template_type == "iou":
if settings["path"]:
if settings.get("path"):
image = await self._find_image(settings["path"])
if image.image_type != "iou":
raise ControllerBadRequestError(