Skip to content

Commit

Permalink
[TASK] Amend query parameter logic for status objects
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 821ecd497376f6420f3c3c74f678617ff33a5102
  • Loading branch information
mckornfield committed Oct 23, 2024
1 parent 033dedd commit de61500
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/rest/ProjectsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ with gretel_client.rest.ApiClient(configuration) as api_client:
api_instance = projects_api.ProjectsApi(api_client)
project_id = "project_id_example" # str | Project id
model_id = "model_id_example" # str | Model id
status = "completed" # str |
status = "status_example" # str |
skip = 1 # int | The number of records being skipped before returning the next set. (optional)
limit = 1 # int | The number of records returned in each result set. (optional)
expand = [
Expand Down
43 changes: 21 additions & 22 deletions src/gretel_client/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,26 +434,25 @@ def _do_cancel_job(self):

def get_record_handlers(self) -> Iterator[RecordHandler]:
"""Returns a list of record handlers associated with the model."""
for status in Status:
# Setting the start value for offset in each query, limiting each result set to 10 records
offset = 0
limit = 10
while True:
handlers = (
self._projects_api.query_record_handlers(
project_id=self.project.project_id,
model_id=self.model_id,
status=status.value,
skip=offset,
limit=limit,
)
.get("data")
.get("handlers")
# Setting the start value for offset in each query, limiting each result set to 10 records
offset = 0
limit = 10
while True:
handlers = (
self._projects_api.query_record_handlers(
project_id=self.project.project_id,
model_id=self.model_id,
skip=offset,
status=",".join(status.value for status in Status),
limit=limit,
)
# will break once no more handlers remain in the result set in the last pagination
if len(handlers) > 0:
for handler in handlers:
yield RecordHandler(self, record_id=handler["uid"])
offset += limit
else:
break
.get("data")
.get("handlers")
)
# will break once no more handlers remain in the result set in the last pagination
if len(handlers) > 0:
for handler in handlers:
yield RecordHandler(self, record_id=handler["uid"])
offset += limit
else:
break
10 changes: 0 additions & 10 deletions src/gretel_client/rest/api/projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2359,23 +2359,13 @@ def __query_record_handlers(self, project_id, model_id, status, **kwargs):
],
"nullable": [],
"enum": [
"status",
"expand",
],
"validation": [],
},
root_map={
"validations": {},
"allowed_values": {
("status",): {
"COMPLETED": "completed",
"ERROR": "error",
"PENDING": "pending",
"ACTIVE": "active",
"LOST": "lost",
"CREATED": "created",
"CANCELLED": "cancelled",
},
("expand",): {"ARTIFACTS": "artifacts"},
},
"openapi_types": {
Expand Down
6 changes: 1 addition & 5 deletions tests/gretel_client/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ def test_goes_through_records(
m.submit(runner_mode=RunnerMode.LOCAL)

def mock_record_handlers(status, skip, limit, *args, **kwargs):
handlers = (
[{"uid": 0} for _ in range(min(limit, num_records - skip))]
if status == "completed"
else []
)
handlers = [{"uid": 0} for _ in range(min(limit, num_records - skip))]
return {"data": {"handlers": handlers}}

m._projects_api.query_record_handlers.side_effect = mock_record_handlers
Expand Down

0 comments on commit de61500

Please sign in to comment.