mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-27 02:32:23 +02:00
fix(templates): Database error detected when saving a template with a disk image change
This commit is contained in:
parent
13d1563762
commit
da3a34144b
@ -48,7 +48,7 @@ class ImagesRepository(BaseRepository):
|
|||||||
else:
|
else:
|
||||||
query = select(models.Image).where(models.Image.filename == image_name)
|
query = select(models.Image).where(models.Image.filename == image_name)
|
||||||
result = await self._db_session.execute(query)
|
result = await self._db_session.execute(query)
|
||||||
return result.scalars().one_or_none()
|
return result.scalars().first()
|
||||||
|
|
||||||
async def get_image_by_checksum(self, checksum: str, image_dir: str = None) -> Optional[models.Image]:
|
async def get_image_by_checksum(self, checksum: str, image_dir: str = None) -> Optional[models.Image]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -124,7 +124,9 @@ class TemplatesRepository(BaseRepository):
|
|||||||
else:
|
else:
|
||||||
query = select(models.Image).where(models.Image.filename == image_name)
|
query = select(models.Image).where(models.Image.filename == image_name)
|
||||||
result = await self._db_session.execute(query)
|
result = await self._db_session.execute(query)
|
||||||
return result.scalars().one_or_none()
|
# Use first() instead of one_or_none() to handle cases where multiple
|
||||||
|
# DB rows share the same filename (e.g. image discovered in multiple paths)
|
||||||
|
return result.scalars().first()
|
||||||
|
|
||||||
async def add_image_to_template(
|
async def add_image_to_template(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@ -267,9 +267,13 @@ class TemplatesService:
|
|||||||
raise ControllerNotFoundError(f"Template '{template_id}' not found")
|
raise ControllerNotFoundError(f"Template '{template_id}' not found")
|
||||||
return template
|
return template
|
||||||
|
|
||||||
async def _remove_image(self, template_id: UUID, image_path:str) -> None:
|
async def _remove_image(self, template_id: UUID, image_path: str) -> None:
|
||||||
|
|
||||||
|
if not image_path:
|
||||||
|
return
|
||||||
image = await self._templates_repo.get_image(image_path)
|
image = await self._templates_repo.get_image(image_path)
|
||||||
|
if image is None:
|
||||||
|
return
|
||||||
await self._templates_repo.remove_image_from_template(template_id, image)
|
await self._templates_repo.remove_image_from_template(template_id, image)
|
||||||
|
|
||||||
async def update_template(self, template_id: UUID, template_update: schemas.TemplateUpdate) -> dict:
|
async def update_template(self, template_id: UUID, template_update: schemas.TemplateUpdate) -> dict:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user