diff --git a/aries_cloudagent/messaging/models/base_record.py b/aries_cloudagent/messaging/models/base_record.py index 44ed51e4fe..35f77baf8e 100644 --- a/aries_cloudagent/messaging/models/base_record.py +++ b/aries_cloudagent/messaging/models/base_record.py @@ -19,7 +19,7 @@ from ..util import datetime_to_str, time_now from ..valid import INDY_ISO8601_DATETIME -from .base import BaseModel, BaseModelSchema +from .base import BaseModel, BaseModelSchema, BaseModelError LOGGER = logging.getLogger(__name__) @@ -329,7 +329,10 @@ async def query( positive=False, alt=alt, ): - result.append(cls.from_storage(record.id, vals)) + try: + result.append(cls.from_storage(record.id, vals)) + except BaseModelError as err: + raise BaseModelError(f"{err}, for record id {record.id}") return result async def save( diff --git a/aries_cloudagent/messaging/models/tests/test_base_record.py b/aries_cloudagent/messaging/models/tests/test_base_record.py index 4caf5dc3d6..87749e2df8 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -12,6 +12,7 @@ StorageError, StorageRecord, ) +from ....messaging.models.base import BaseModelError from ...util import time_now @@ -181,6 +182,26 @@ async def test_query(self): assert result[0]._id == record_id assert result[0].value == record_value + async def test_query_x(self): + session = InMemoryProfile.test_session() + mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + session.context.injector.bind_instance(BaseStorage, mock_storage) + record_id = "record_id" + record_value = {"created_at": time_now(), "updated_at": time_now()} + tag_filter = {"tag": "filter"} + stored = StorageRecord( + BaseRecordImpl.RECORD_TYPE, json.dumps(record_value), {}, record_id + ) + + mock_storage.find_all_records.return_value = [stored] + with async_mock.patch.object( + BaseRecordImpl, + "from_storage", + async_mock.MagicMock(side_effect=BaseModelError), + ): + with self.assertRaises(BaseModelError): + await BaseRecordImpl.query(session, tag_filter) + async def test_query_post_filter(self): session = InMemoryProfile.test_session() mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/routes.py b/aries_cloudagent/protocols/present_proof/v2_0/routes.py index a74b9203d4..115bf09d08 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/routes.py @@ -32,6 +32,7 @@ UUID4, ) from ....storage.error import StorageError, StorageNotFoundError +from ....storage.base import BaseStorage from ....storage.vc_holder.base import VCHolder from ....storage.vc_holder.vc_record import VCRecord from ....utils.tracing import trace_event, get_timer, AdminAPIMessageTracingSchema @@ -1265,8 +1266,17 @@ async def present_proof_remove(request: web.BaseRequest): pres_ex_record = None try: async with context.profile.session() as session: - pres_ex_record = await V20PresExRecord.retrieve_by_id(session, pres_ex_id) - await pres_ex_record.delete_record(session) + try: + pres_ex_record = await V20PresExRecord.retrieve_by_id( + session, pres_ex_id + ) + await pres_ex_record.delete_record(session) + except (BaseModelError, ValidationError): + storage = session.inject(BaseStorage) + storage_record = await storage.get_record( + record_type=V20PresExRecord.RECORD_TYPE, record_id=pres_ex_id + ) + await storage.delete_record(storage_record) except StorageNotFoundError as err: raise web.HTTPNotFound(reason=err.roll_up) from err except StorageError as err: