Skip to content

Commit

Permalink
fix(BA-454): Directly retrieve VFolder by folder ID in purge API (#3388
Browse files Browse the repository at this point in the history
…) (#3428)

Co-authored-by: Sanghun Lee <[email protected]>
  • Loading branch information
lablup-octodog and fregataa authored Jan 11, 2025
1 parent faac53e commit 82f1d93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions changes/3388.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix purge API to allow deletion of owner-deleted VFolders by directly retrieving VFolders using the folder ID
25 changes: 9 additions & 16 deletions src/ai/backend/manager/api/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
VFolderPermissionRow,
delete_vfolder_relation_rows,
)
from ..models.vfolder import VFolderRow as VFolderDBRow
from .auth import admin_required, auth_required, superadmin_required
from .exceptions import (
BackendAgentError,
Expand Down Expand Up @@ -2568,22 +2569,14 @@ async def purge(request: web.Request, params: PurgeRequestModel) -> web.Response
):
raise InsufficientPrivilege("You are not allowed to purge vfolders")

row = (
await resolve_vfolder_rows(
request,
VFolderPermission.OWNER_PERM,
folder_id,
allowed_status_set=VFolderStatusSet.PURGABLE,
allow_privileged_access=True,
)
)[0]
await check_vfolder_status(row, VFolderStatusSet.PURGABLE)

async with root_ctx.db.begin() as conn:
# query_accesible_vfolders returns list
entry = row
delete_stmt = sa.delete(vfolders).where(vfolders.c.id == entry["id"])
await conn.execute(delete_stmt)
async with root_ctx.db.begin_session() as db_session:
row = await db_session.scalar(sa.select(VFolderDBRow).where(VFolderDBRow.id == folder_id))
row = cast(VFolderDBRow | None, row)
if row is None:
raise VFolderNotFound(extra_data=folder_id)
await check_vfolder_status({"status": row.status}, VFolderStatusSet.PURGABLE)
delete_stmt = sa.delete(VFolderDBRow).where(VFolderDBRow.id == folder_id)
await db_session.execute(delete_stmt)

return web.Response(status=204)

Expand Down

0 comments on commit 82f1d93

Please sign in to comment.