Skip to content

Commit

Permalink
Log instead of failing during file removal
Browse files Browse the repository at this point in the history
  • Loading branch information
iharsuvorau committed Jan 31, 2024
1 parent 6149524 commit b079e5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion backend/services/api-server/api_server/assets/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
import uuid
from typing import AsyncGenerator, Optional, Sequence

Expand All @@ -10,6 +11,8 @@
from api_server.files.model import File
from api_server.files.service import FileService, get_file_service

logger = logging.getLogger()


class AssetService:
def __init__(
Expand Down Expand Up @@ -92,7 +95,10 @@ async def delete_asset(self, asset_id: uuid.UUID) -> None:
asset = await self.get_asset(asset_id)
await self.asset_repository.delete_asset(asset_id)
for file_id in asset.files_ids:
await self.file_service.delete_file(file_id)
try:
await self.file_service.delete_file(file_id)
except Exception as e:
logger.error(f"Failed to delete file {file_id}: {e}")

async def delete_assets_by_project_id(self, project_id: uuid.UUID) -> None:
assets = await self.get_assets_by_project_id(project_id)
Expand Down
6 changes: 4 additions & 2 deletions backend/services/api-server/api_server/projects/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import logging
import uuid
from email import message
from typing import AsyncGenerator, Optional, Sequence

from fastapi import Depends
Expand All @@ -12,6 +12,8 @@
from api_server.projects.repository import ProjectRepository, get_project_repository
from api_server.users.users import UserManager, get_user_manager

logger = logging.getLogger() # noqa: F821


class UserNotFound(Exception):
pass
Expand Down Expand Up @@ -155,7 +157,7 @@ async def delete_project(self, project_id: uuid.UUID) -> None:
try:
await self._asset_service.delete_assets_by_project_id(project_id)
except Exception as e:
raise AssetDeletionFailed(f"Failed to delete assets of project {project_id}: {e}")
logger.exception(f"Failed to delete assets of project {project_id}: {e}")

await self._project_repository.delete_project(project_id)

Expand Down

0 comments on commit b079e5b

Please sign in to comment.