diff --git a/acapy_agent/messaging/models/paginated_query.py b/acapy_agent/messaging/models/paginated_query.py index b938af772d..670c3cda2b 100644 --- a/acapy_agent/messaging/models/paginated_query.py +++ b/acapy_agent/messaging/models/paginated_query.py @@ -46,7 +46,10 @@ class PaginatedQuerySchema(OpenAPISchema): descending = fields.Bool( required=False, load_default=False, + truthy={"true", "1", "yes"}, + falsy={"false", "0", "no"}, metadata={"description": "Order results in descending order if true"}, + error_messages={"invalid": "Not a valid boolean."}, ) @@ -67,5 +70,9 @@ def get_paginated_query_params(request: BaseRequest) -> Tuple[int, int, str, boo limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE)) offset = int(request.query.get("offset", 0)) order_by = request.query.get("order_by", "id") - descending = bool(request.query.get("descending", False)) + + # Convert the 'descending' parameter to a boolean + descending_str = request.query.get("descending", "False").lower() + descending = descending_str in {"true", "1", "yes"} + return limit, offset, order_by, descending diff --git a/acapy_agent/messaging/models/tests/test_base_record.py b/acapy_agent/messaging/models/tests/test_base_record.py index 36bf7fa7db..672705dfd7 100644 --- a/acapy_agent/messaging/models/tests/test_base_record.py +++ b/acapy_agent/messaging/models/tests/test_base_record.py @@ -164,9 +164,9 @@ async def test_query(self): result = await BaseRecordImpl.query(session, tag_filter) mock_storage.find_all_records.assert_awaited_once_with( type_filter=BaseRecordImpl.RECORD_TYPE, - tag_query=tag_filter, order_by=None, descending=False, + tag_query=tag_filter, ) assert result and isinstance(result[0], BaseRecordImpl) assert result[0]._id == record_id diff --git a/acapy_agent/multitenant/admin/routes.py b/acapy_agent/multitenant/admin/routes.py index a569902ad4..470e4e059b 100644 --- a/acapy_agent/multitenant/admin/routes.py +++ b/acapy_agent/multitenant/admin/routes.py @@ -399,7 +399,6 @@ async def wallets_list(request: web.BaseRequest): descending=descending, ) results = [format_wallet_record(record) for record in records] - results.sort(key=lambda w: w["created_at"]) except (StorageError, BaseModelError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err diff --git a/acapy_agent/multitenant/admin/tests/test_routes.py b/acapy_agent/multitenant/admin/tests/test_routes.py index 87dcdde88d..de989bf2b4 100644 --- a/acapy_agent/multitenant/admin/tests/test_routes.py +++ b/acapy_agent/multitenant/admin/tests/test_routes.py @@ -87,7 +87,7 @@ async def test_wallets_list(self): ), ] mock_wallet_record.query = mock.CoroutineMock() - mock_wallet_record.query.return_value = [wallets[2], wallets[0], wallets[1]] + mock_wallet_record.query.return_value = wallets await test_module.wallets_list(self.request) mock_response.assert_called_once_with( diff --git a/acapy_agent/protocols/connections/v1_0/routes.py b/acapy_agent/protocols/connections/v1_0/routes.py index bafe178ede..8277484e40 100644 --- a/acapy_agent/protocols/connections/v1_0/routes.py +++ b/acapy_agent/protocols/connections/v1_0/routes.py @@ -414,20 +414,6 @@ class EndpointsResultSchema(OpenAPISchema): ) -def connection_sort_key(conn): - """Get the sorting key for a particular connection.""" - - conn_rec_state = ConnRecord.State.get(conn["state"]) - if conn_rec_state is ConnRecord.State.ABANDONED: - pfx = "2" - elif conn_rec_state is ConnRecord.State.INVITATION: - pfx = "1" - else: - pfx = "0" - - return pfx + conn["created_at"] - - @docs( tags=["connection"], summary="Query agent-to-agent connections", @@ -488,7 +474,6 @@ async def connections_list(request: web.BaseRequest): alt=True, ) results = [record.serialize() for record in records] - results.sort(key=connection_sort_key) except (StorageError, BaseModelError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err diff --git a/acapy_agent/protocols/connections/v1_0/tests/test_routes.py b/acapy_agent/protocols/connections/v1_0/tests/test_routes.py index 7ae1129a19..05e279e75b 100644 --- a/acapy_agent/protocols/connections/v1_0/tests/test_routes.py +++ b/acapy_agent/protocols/connections/v1_0/tests/test_routes.py @@ -87,7 +87,7 @@ async def test_connections_list(self): ) ), ] - mock_conn_rec.query.return_value = [conns[2], conns[0], conns[1]] # jumbled + mock_conn_rec.query.return_value = conns with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.connections_list(self.request)