Skip to content

Commit a3725c4

Browse files
authored
remove file limit (#745)
* fix * remove limits tests
1 parent 07c5b8e commit a3725c4

File tree

4 files changed

+1
-131
lines changed

4 files changed

+1
-131
lines changed

src/backend/routers/agent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from backend.services.file import (
5252
consolidate_agent_files_in_compass,
5353
get_file_service,
54-
validate_batch_file_size,
5554
validate_file,
5655
)
5756
from backend.services.request_validators import (
@@ -686,7 +685,6 @@ async def batch_upload_file(
686685
ctx: Context = Depends(get_context),
687686
) -> UploadAgentFileResponse:
688687
user_id = ctx.get_user_id()
689-
validate_batch_file_size(session, user_id, files)
690688

691689
uploaded_files = []
692690
try:

src/backend/routers/conversation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from backend.services.file import (
3838
attach_conversation_id_to_files,
3939
get_file_service,
40-
validate_batch_file_size,
4140
validate_file,
4241
)
4342

@@ -346,7 +345,6 @@ async def batch_upload_file(
346345
"""
347346

348347
user_id = ctx.get_user_id()
349-
validate_batch_file_size(session, user_id, files)
350348

351349
# Create new conversation
352350
if not conversation_id:

src/backend/services/file.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -738,62 +738,3 @@ def read_docx(file_contents: bytes) -> str:
738738
text += paragraph.text + "\n"
739739

740740
return text
741-
742-
743-
def validate_file_size(
744-
session: DBSessionDep, user_id: str, file: FastAPIUploadFile
745-
) -> None:
746-
"""Validates the file size
747-
748-
Args:
749-
user_id (str): The user ID
750-
file (UploadFile): The file to validate
751-
752-
Raises:
753-
HTTPException: If the file size is too large
754-
"""
755-
if file.size > MAX_FILE_SIZE:
756-
raise HTTPException(
757-
status_code=400,
758-
detail=f"File size exceeds the maximum allowed size of {MAX_FILE_SIZE} bytes.",
759-
)
760-
761-
existing_files = file_crud.get_files_by_user_id(session, user_id)
762-
total_file_size = sum([f.file_size for f in existing_files]) + file.size
763-
764-
if total_file_size > MAX_TOTAL_FILE_SIZE:
765-
raise HTTPException(
766-
status_code=400,
767-
detail=f"Total file size exceeds the maximum allowed size of {MAX_TOTAL_FILE_SIZE} bytes.",
768-
)
769-
770-
771-
def validate_batch_file_size(
772-
session: DBSessionDep, user_id: str, files: list[FastAPIUploadFile]
773-
) -> None:
774-
"""Validate sizes of files in batch
775-
776-
Args:
777-
user_id (str): The user ID
778-
files (list[FastAPIUploadFile]): The files to validate
779-
780-
Raises:p
781-
HTTPException: If the file size is too large
782-
"""
783-
total_batch_size = 0
784-
for file in files:
785-
if file.size > MAX_FILE_SIZE:
786-
raise HTTPException(
787-
status_code=400,
788-
detail=f"{file.filename} exceeds the maximum allowed size of {MAX_FILE_SIZE} bytes.",
789-
)
790-
total_batch_size += file.size
791-
792-
existing_files = file_crud.get_files_by_user_id(session, user_id)
793-
total_file_size = sum([f.file_size for f in existing_files]) + total_batch_size
794-
795-
if total_file_size > MAX_TOTAL_FILE_SIZE:
796-
raise HTTPException(
797-
status_code=400,
798-
detail=f"Total file size exceeds the maximum allowed size of {MAX_TOTAL_FILE_SIZE} bytes.",
799-
)

src/backend/tests/unit/routers/test_conversation.py

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Message,
1313
)
1414
from backend.schemas.user import User
15-
from backend.services.file import MAX_FILE_SIZE, MAX_TOTAL_FILE_SIZE, get_file_service
15+
from backend.services.file import get_file_service
1616
from backend.tests.unit.factories import get_factory
1717

1818

@@ -594,73 +594,6 @@ def test_batch_upload_file_existing_conversation(
594594
assert len(files_stored) == len(file_paths)
595595

596596

597-
def test_batch_upload_total_files_exceeds_limit(
598-
session_client: TestClient, session: Session, user, mock_compass_settings
599-
) -> None:
600-
_ = get_factory("Conversation", session).create(user_id=user.id)
601-
file_paths = {
602-
"Mariana_Trench.pdf": "src/backend/tests/unit/test_data/Mariana_Trench.pdf",
603-
"Cardistry.pdf": "src/backend/tests/unit/test_data/Cardistry.pdf",
604-
"Tapas.pdf": "src/backend/tests/unit/test_data/Tapas.pdf",
605-
"Mount_Everest.pdf": "src/backend/tests/unit/test_data/Mount_Everest.pdf",
606-
}
607-
files = [
608-
("files", (file_name, open(file_path, "rb")))
609-
for file_name, file_path in file_paths.items()
610-
]
611-
612-
conversation = get_factory("Conversation", session).create(user_id=user.id)
613-
file = get_factory("File", session).create(
614-
file_name="test_file.txt",
615-
user_id=conversation.user_id,
616-
file_size=1000000000,
617-
)
618-
_ = get_factory("ConversationFileAssociation", session).create(
619-
conversation_id=conversation.id, user_id=user.id, file_id=file.id
620-
)
621-
622-
response = session_client.post(
623-
"/v1/conversations/batch_upload_file",
624-
files=files,
625-
headers={"User-Id": conversation.user_id},
626-
)
627-
628-
assert response.status_code == 400
629-
assert response.json() == {
630-
"detail": f"Total file size exceeds the maximum allowed size of {MAX_TOTAL_FILE_SIZE} bytes."
631-
}
632-
633-
634-
def test_batch_upload_single_file_exceeds_limit(
635-
session_client: TestClient, session: Session, user, mock_compass_settings
636-
) -> None:
637-
_ = get_factory("Conversation", session).create(user_id=user.id)
638-
file_paths = {
639-
"Mariana_Trench.pdf": "src/backend/tests/unit/test_data/Mariana_Trench.pdf",
640-
"Cardistry.pdf": "src/backend/tests/unit/test_data/Cardistry.pdf",
641-
"26mb.pdf": "src/backend/tests/unit/test_data/26mb.pdf",
642-
"Tapas.pdf": "src/backend/tests/unit/test_data/Tapas.pdf",
643-
"Mount_Everest.pdf": "src/backend/tests/unit/test_data/Mount_Everest.pdf",
644-
}
645-
files = [
646-
("files", (file_name, open(file_path, "rb")))
647-
for file_name, file_path in file_paths.items()
648-
]
649-
650-
conversation = get_factory("Conversation", session).create(user_id=user.id)
651-
652-
response = session_client.post(
653-
"/v1/conversations/batch_upload_file",
654-
files=files,
655-
headers={"User-Id": conversation.user_id},
656-
)
657-
658-
assert response.status_code == 400
659-
assert response.json() == {
660-
"detail": f"26mb.pdf exceeds the maximum allowed size of {MAX_FILE_SIZE} bytes."
661-
}
662-
663-
664597
def test_batch_upload_file_nonexistent_conversation_creates_new_conversation(
665598
session_client: TestClient, session: Session, user, mock_compass_settings
666599
) -> None:

0 commit comments

Comments
 (0)