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"] )