Skip to content

Commit c9e09d9

Browse files
authored
Update files.py
1 parent 1ec41a0 commit c9e09d9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎app/controllers/files.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
from sqlalchemy.orm import Session
2020

2121
from ..infra.config import conversation_workspace
22+
from ..infra.db import commit_now
2223
from ..models import Conversation, ConversationFile, User, new_id
23-
from ..models.db import commit_now
24+
from .access import get_owned
2425
from .errors import InvalidRequest, NotFound, PayloadTooLarge
2526

2627
MAX_UPLOAD_BYTES = 100 * 1024 * 1024
@@ -87,9 +88,14 @@ async def store_upload(
8788

8889
def delete_upload(db: Session, conversation: Conversation, file_id: str) -> None:
8990
"""Forget an upload and unlink it from the workspace."""
90-
row = db.get(ConversationFile, file_id)
91-
if row is None or row.conversation_id != conversation.id:
92-
raise NotFound("file not found")
91+
row = get_owned(
92+
db,
93+
ConversationFile,
94+
file_id,
95+
owner_field="conversation_id",
96+
owner_value=conversation.id,
97+
detail="file not found",
98+
)
9399
with contextlib.suppress(OSError):
94100
Path(row.path).unlink()
95101
db.delete(row)

0 commit comments

Comments
 (0)