jroachgolf84 commented on code in PR #55070: URL: https://github.com/apache/airflow/pull/55070#discussion_r2359635154
########## providers/amazon/src/airflow/providers/amazon/aws/sensors/s3.py: ########## @@ -122,8 +122,20 @@ def _check_key(self, key, context: Context): """ if self.wildcard_match: prefix = re.split(r"[\[*?]", key, 1)[0] - keys = self.hook.get_file_metadata(prefix, bucket_name) - key_matches = [k for k in keys if fnmatch.fnmatch(k["Key"], key)] + + key_matches: list[str] = [] + + # Is check_fn is None, then we can return True without having to iterate through each value in + # yielded by iter_file_metadata. Otherwise, we'll check for a match, and add all matches to the + # key_matches list + for k in self.hook.iter_file_metadata(prefix, bucket_name): + if fnmatch.fnmatch(k["Key"], key): + if self.check_fn is not None: + key_matches.append(k) + # This will only wait for a single match, and will immediately return + else: + return True Review Comment: Thanks - this wasn't my prettiest code :) -- 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-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org