Skip to content

Commit 35696eb

Browse files
committed
submissionBundle methods return generators
1 parent 7add157 commit 35696eb

File tree

7 files changed

+434
-401
lines changed

7 files changed

+434
-401
lines changed

synapseclient/api/evaluation_services.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -783,29 +783,23 @@ async def batch_update_submission_statuses(
783783
async def get_evaluation_submission_bundles(
784784
evaluation_id: str,
785785
status: Optional[str] = None,
786-
limit: int = 10,
787-
offset: int = 0,
786+
*,
788787
synapse_client: Optional["Synapse"] = None,
789-
) -> dict:
788+
) -> AsyncGenerator[Dict[str, Any], None]:
790789
"""
791-
Gets a collection of bundled Submissions and SubmissionStatuses to a given Evaluation.
790+
Generator to get all bundled Submissions and SubmissionStatuses to a given Evaluation.
792791
793792
<https://rest-docs.synapse.org/rest/GET/evaluation/evalId/submission/bundle/all.html>
794793
795794
Arguments:
796795
evaluation_id: The ID of the specified Evaluation.
797796
status: Optionally filter submission bundles by status.
798-
limit: Limits the number of entities that will be fetched for this page.
799-
When null it will default to 10, max value 100. Default to 10.
800-
offset: The offset index determines where this page will start from.
801-
An index of 0 is the first entity. Default to 0.
802797
synapse_client: If not passed in and caching was not disabled by
803798
`Synapse.allow_client_caching(False)` this will use the last created
804799
instance from the Synapse class constructor.
805800
806-
Returns:
807-
A PaginatedResults<SubmissionBundle> object as a JSON dict containing
808-
a paginated list of submission bundles for the evaluation queue.
801+
Yields:
802+
Individual SubmissionBundle objects from each page of the response.
809803
810804
Note:
811805
The caller must be granted the ACCESS_TYPE.READ_PRIVATE_SUBMISSION on the specified Evaluation.
@@ -815,48 +809,44 @@ async def get_evaluation_submission_bundles(
815809
client = Synapse.get_client(synapse_client=synapse_client)
816810

817811
uri = f"/evaluation/{evaluation_id}/submission/bundle/all"
818-
query_params = {"limit": limit, "offset": offset}
812+
query_params = {}
819813

820814
if status:
821815
query_params["status"] = status
822816

823-
response = await client.rest_get_async(uri, params=query_params)
824-
825-
return response
817+
async for item in rest_get_paginated_async(
818+
uri=uri, params=query_params, synapse_client=client
819+
):
820+
yield item
826821

827822

828823
async def get_user_submission_bundles(
829824
evaluation_id: str,
830-
limit: int = 10,
831-
offset: int = 0,
825+
*,
832826
synapse_client: Optional["Synapse"] = None,
833-
) -> dict:
827+
) -> AsyncGenerator[Dict[str, Any], None]:
834828
"""
835-
Gets the requesting user's bundled Submissions and SubmissionStatuses to a specified Evaluation.
829+
Generator to get all user bundled Submissions and SubmissionStatuses for a specified Evaluation.
836830
837831
<https://rest-docs.synapse.org/rest/GET/evaluation/evalId/submission/bundle.html>
838832
839833
Arguments:
840834
evaluation_id: The ID of the specified Evaluation.
841-
limit: Limits the number of entities that will be fetched for this page.
842-
When null it will default to 10. Default to 10.
843-
offset: The offset index determines where this page will start from.
844-
An index of 0 is the first entity. Default to 0.
845835
synapse_client: If not passed in and caching was not disabled by
846836
`Synapse.allow_client_caching(False)` this will use the last created
847837
instance from the Synapse class constructor.
848838
849-
Returns:
850-
A PaginatedResults<SubmissionBundle> object as a JSON dict containing
851-
a paginated list of the requesting user's submission bundles for the evaluation queue.
839+
Yields:
840+
Individual SubmissionBundle objects from each page of the response.
852841
"""
853842
from synapseclient import Synapse
854843

855844
client = Synapse.get_client(synapse_client=synapse_client)
856845

857846
uri = f"/evaluation/{evaluation_id}/submission/bundle"
858-
query_params = {"limit": limit, "offset": offset}
859-
860-
response = await client.rest_get_async(uri, params=query_params)
847+
query_params = {}
861848

862-
return response
849+
async for item in rest_get_paginated_async(
850+
uri=uri, params=query_params, synapse_client=client
851+
):
852+
yield item

synapseclient/models/submission.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ async def get_submission_example():
651651

652652
return self
653653

654-
# TODO: Have all staticmethods return generators for pagination
655654
@skip_async_to_sync
656655
@classmethod
657656
async def get_evaluation_submissions_async(

0 commit comments

Comments
 (0)