bugraoz93 commented on code in PR #50132:
URL: https://github.com/apache/airflow/pull/50132#discussion_r2226249482


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -147,6 +150,39 @@ 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: str,
+        data_model: type[T],
+        offset: int = 0,
+        limit: int = 50,
+        params: dict | None = None,
+    ) -> T | ServerResponseError:
+        shared_params = {**(params or {})}
+        try:
+            self.response = self.client.get(path, params=shared_params)
+            first_pass = data_model.model_validate_json(self.response.content)
+            total_entries = first_pass.total_entries  # type: 
ignore[attr-defined]
+            if total_entries < limit:
+                print(first_pass)

Review Comment:
   ```suggestion
   ```



##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -147,6 +150,39 @@ 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: str,
+        data_model: type[T],
+        offset: int = 0,
+        limit: int = 50,
+        params: dict | None = None,
+    ) -> T | ServerResponseError:
+        shared_params = {**(params or {})}
+        try:
+            self.response = self.client.get(path, params=shared_params)
+            first_pass = data_model.model_validate_json(self.response.content)
+            total_entries = first_pass.total_entries  # type: 
ignore[attr-defined]
+            if total_entries < limit:
+                print(first_pass)
+                return first_pass
+            for key, value in first_pass.model_dump().items():
+                if key != "total_entries" and isinstance(value, list):
+                    break
+            entry_list = getattr(first_pass, key)
+            offset = offset + limit
+            while offset < total_entries:
+                loop_params = {**shared_params, "offset": offset}
+                self.response = self.client.get(path, params=loop_params)

Review Comment:
   ```suggestion
                   self.response = self.client.get(path, 
params={**shared_params, "offset": offset})
   ```
   
   Nit, we don't need the variable, which can reduce LoC



-- 
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]

Reply via email to