aaron-y-chen commented on code in PR #69627:
URL: https://github.com/apache/airflow/pull/69627#discussion_r3742697613
##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -207,35 +207,44 @@ def __init_subclass__(cls, **kwargs):
if callable(value):
setattr(cls, attr,
_check_flag_and_exit_if_server_response_error(value))
- def execute_list(self, *, path, data_model, offset=0, limit=50,
params=None):
- if limit <= 0:
+ def execute_list(self, *, path, data_model, offset=0, limit=None,
params=None):
+ page_size = 50
+ if params:
+ limit = params.pop("limit", limit)
+ offset = params.pop("offset", offset)
+ if limit is not None and limit <= 0:
raise ValueError(f"limit must be a positive integer, got {limit}")
- shared_params = {"limit": limit, **(params or {})}
-
def safe_validate(content: bytes) -> BaseModel:
try:
return data_model.model_validate_json(content) # type:
ignore[union-attr]
except ValidationError:
raw = fill_missing_fields(json.loads(content), data_model)
return data_model.model_validate(raw) # type:
ignore[union-attr]
- self.response = self.client.get(path, params={**shared_params,
"offset": offset})
+ first_size = page_size if limit is None else min(limit, page_size)
+ shared_params = {"limit": first_size, "offset": offset, **(params or
{})}
+ self.response = self.client.get(path, params=shared_params)
first_pass = safe_validate(self.response.content)
total_entries = first_pass.total_entries # type: ignore[attr-defined]
- if total_entries < limit:
+ if first_size < page_size:
return first_pass
found_key = None
for key, value in first_pass.model_dump().items():
if key != "total_entries" and isinstance(value, list):
found_key = key
break
entry_list = getattr(first_pass, found_key)
- offset = offset + limit
+ if limit:
+ total_entries = min(limit, total_entries) + offset
Review Comment:
What if `total_entries = 200`, `offset = 150`, and `limit = 100`?
According to this line, `total_entries` would become `250`. Is that expected?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]