You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/03/08 05:03:29 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #29732: Loop through paginated response to check for cluster id

uranusjr commented on code in PR #29732:
URL: https://github.com/apache/airflow/pull/29732#discussion_r1128979153


##########
airflow/providers/amazon/aws/hooks/emr.py:
##########
@@ -69,11 +69,14 @@ def get_cluster_id_by_name(self, emr_cluster_name: str, cluster_states: list[str
         :param cluster_states: State(s) of cluster to find
         :return: id of the EMR cluster
         """
-        response = self.get_conn().list_clusters(ClusterStates=cluster_states)
-
-        matching_clusters = list(
-            filter(lambda cluster: cluster["Name"] == emr_cluster_name, response["Clusters"])
+        response_iterator = (
+            self.get_conn().get_paginator("list_clusters").paginate(ClusterStates=cluster_states)
         )
+        matching_clusters = []
+        for page in response_iterator:
+            matching_clusters.extend(
+                list(filter(lambda cluster: cluster["Name"] == emr_cluster_name, page["Clusters"]))
+            )

Review Comment:
   ```suggestion
           matching_clusters = [
               cluster
               for page in response_iterator
               for cluster in page["Clusters"]
               if cluster["Name"] == emr_cluster_name
           ]
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org