feluelle commented on pull request #11747:
URL: https://github.com/apache/airflow/pull/11747#issuecomment-721557634
> Why don't use `NamedTemporaryFile` to avoid `local_file_path` ?
@TobKed, I think you are right. That is better, because it takes more
control over the existence of the temporarily file. It is important that this
file will be deleted. In the current code (my previous suggestion) the file
won't be deleted for example if the ftp_conn_id is missing. The `try`-`finally`
is a bad decision if we can do it through context manager of NamedTemporaryFile
already - we just cannot use `s3_hook.download_file` and instead must stick to
using boto api (`s3_obj.download_fileobj`) directly.
```python
s3_obj = self.get_key(key, bucket_name)
with NamedTemporaryFile() as local_tmp_file:
s3_obj.download_fileobj(local_tmp_file)
ftp_hook.store_file(self.ftp_path, local_tmp_file.name)
```
WDYT @JavierLopezT ?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]