From f645bb89009a91ecdbd8c1a4292827e778ab9af8 Mon Sep 17 00:00:00 2001 From: rowan04 Date: Mon, 9 Dec 2024 16:36:44 +0000 Subject: [PATCH] Revert "Move invalid entity_id error handling for list attachments into repositories layer" This reverts commit a3911ffb92705acbc490d1e43e6f6462e77625d1. --- object_storage_api/repositories/attachment.py | 10 +--------- test/e2e/test_attachment.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/object_storage_api/repositories/attachment.py b/object_storage_api/repositories/attachment.py index d218cd7..3b3502b 100644 --- a/object_storage_api/repositories/attachment.py +++ b/object_storage_api/repositories/attachment.py @@ -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() @@ -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: diff --git a/test/e2e/test_attachment.py b/test/e2e/test_attachment.py index 7c64e88..eded8ec 100644 --- a/test/e2e/test_attachment.py +++ b/test/e2e/test_attachment.py @@ -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"] )