o-nikolas commented on code in PR #26886:
URL: https://github.com/apache/airflow/pull/26886#discussion_r988383168


##########
airflow/providers/amazon/aws/hooks/s3.py:
##########
@@ -879,14 +880,23 @@ def delete_objects(self, bucket: str, keys: str | list) 
-> None:
 
     @provide_bucket_name
     @unify_bucket_name_and_key
-    def download_file(self, key: str, bucket_name: str | None = None, 
local_path: str | None = None) -> str:
+    def download_file(
+        self,
+        key: str,
+        bucket_name: str | None = None,
+        local_path: str | None = None,
+        preserve_file_name: bool = False,
+    ) -> str:
         """
         Downloads a file from the S3 location to the local file system.
 
         :param key: The key path in S3.
         :param bucket_name: The specific bucket to use.
         :param local_path: The local path to the downloaded file. If no path 
is provided it will use the
             system's temporary directory.
+        :param preserve_file_name: If you want the downloaded file name to be 
with the same name as in S3, set
+            this parameter to True. When set to False, a random filename will 
be generated.

Review Comment:
   ```suggestion
           :param preserve_file_name: If you want the downloaded file name to 
be the same name as it is in S3, set
               this parameter to True. When set to False, a random filename 
will be generated.
   ```



##########
airflow/providers/amazon/aws/hooks/s3.py:
##########
@@ -909,7 +919,17 @@ def download_file(self, key: str, bucket_name: str | None 
= None, local_path: st
                 Config=self.transfer_config,
             )
 
-        return local_tmp_file.name
+        if preserve_file_name:

Review Comment:
   It feels to me like the conditional should happen earlier, before the 
temporary file name is created, it's a bit strange to change the name 
afterwards when we could just download it under the correct name (whether temp 
or not) in the first place.
   
   This would require a greater refactoring of this code though.



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