fix(app): when creating image, skip adding to board if board doesn't exist

Before this change, if you attempt to create an image that with a nonexistent board, we'd get an unhandled error when adding the image to a board. The record would be created, but file not, due to the structure of the code.

With this change, we now log a warning if we have a problem adding the image to the board, but the record and file are still created.

A future improvement would be to create a transaction for this part of the code, preventing some other situation that could result in only the record or only the file beings saved.
This commit is contained in:
psychedelicious 2024-06-28 09:18:28 +10:00
parent b5f23292d4
commit 9f93e9d120

View File

@ -73,7 +73,12 @@ class ImageService(ImageServiceABC):
session_id=session_id, session_id=session_id,
) )
if board_id is not None: if board_id is not None:
self.__invoker.services.board_image_records.add_image_to_board(board_id=board_id, image_name=image_name) try:
self.__invoker.services.board_image_records.add_image_to_board(
board_id=board_id, image_name=image_name
)
except Exception as e:
self.__invoker.services.logger.warn(f"Failed to add image to board {board_id}: {str(e)}")
self.__invoker.services.image_files.save( self.__invoker.services.image_files.save(
image_name=image_name, image=image, metadata=metadata, workflow=workflow, graph=graph image_name=image_name, image=image, metadata=metadata, workflow=workflow, graph=graph
) )