Skip to content

Commit

Permalink
Revert "Move invalid entity_id error handling for list attachments in…
Browse files Browse the repository at this point in the history
…to repositories layer"

This reverts commit a3911ff.
  • Loading branch information
rowan04 committed Dec 9, 2024
1 parent a3911ff commit f645bb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions object_storage_api/repositories/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from object_storage_api.core.custom_object_id import CustomObjectId
from object_storage_api.core.database import DatabaseDep
from object_storage_api.core.exceptions import InvalidObjectIdError
from object_storage_api.models.attachment import AttachmentIn, AttachmentOut

logger = logging.getLogger()
Expand Down Expand Up @@ -65,21 +64,14 @@ def list(self, entity_id: Optional[str], session: ClientSession = None) -> list[
:param session: PyMongo ClientSession to use for database operations.
:param entity_id: The ID of the entity to filter attachments by.
:return: List of attachments or an empty list if no attachments are retrieved.
:raises InvalidObjectIdError: If the supplied `entity_id` is invalid.
"""

# There is some duplicate code here, due to the attachments and images methods being very similar
# pylint: disable=duplicate-code

query = {}

if entity_id is not None:
try:
query["entity_id"] = CustomObjectId(entity_id)
except InvalidObjectIdError as exc:
exc.status_code = 422
exc.response_detail = "Attachment not found"
raise exc
query["entity_id"] = CustomObjectId(entity_id)

message = "Retrieving all attachments from the database"
if not query:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ def test_list_with_invalid_entity_id_filter(self):
self.post_test_attachments()
self.get_attachments(filters={"entity_id": False})
self.check_get_attachments_failed_with_message(
422, "Attachment not found", self._get_response_attachment.json()["detail"]
422, "Invalid ID given", self._get_response_attachment.json()["detail"]
)

0 comments on commit f645bb8

Please sign in to comment.