From f376c704f393ed4e1e868d4a840da8358baffa42 Mon Sep 17 00:00:00 2001 From: Andrea Bonomi Date: Thu, 25 Aug 2022 07:07:44 +0000 Subject: [PATCH] Fix send_file exception for new version of Flask --- airflow_code_editor/VERSION | 2 +- airflow_code_editor/fs.py | 26 ++++++++++++++++++-------- changelog.txt | 8 ++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/airflow_code_editor/VERSION b/airflow_code_editor/VERSION index 66ce77b..9fe9ff9 100644 --- a/airflow_code_editor/VERSION +++ b/airflow_code_editor/VERSION @@ -1 +1 @@ -7.0.0 +7.0.1 diff --git a/airflow_code_editor/fs.py b/airflow_code_editor/fs.py index 08675c3..5ceb6f3 100644 --- a/airflow_code_editor/fs.py +++ b/airflow_code_editor/fs.py @@ -200,18 +200,28 @@ def send_file(self, as_attachment: bool): raise FileNotFoundError(errno.ENOENT, 'File not found', self.path) elif self.root_fs.hassyspath(self.path): # Local filesystem - return send_file( - self.root_fs.getsyspath(self.path), - as_attachment=as_attachment, - attachment_filename=self.name if as_attachment else None, - ) + if as_attachment: + # Send file as attachment (set Content-Disposition: attachment header) + try: + # flask >= 2.0 - download_name replaces the attachment_filename + return send_file( + self.root_fs.getsyspath(self.path), + as_attachment=True, + download_name=self.name, + ) + except TypeError: + return send_file( + self.root_fs.getsyspath(self.path), + as_attachment=True, + ) + else: + return send_file(self.root_fs.getsyspath(self.path)) else: # Other filesystems response = Response(stream_with_context(self.read_file_chunks())) if as_attachment: - response.headers[ - 'Content-Disposition' - ] = 'attachment;filename={}'.format(self.name) + content_disposition = 'attachment;filename={}'.format(self.name) + response.headers['Content-Disposition'] = content_disposition return response def write_file(self, data: Union[str, bytes], is_text: bool) -> None: diff --git a/changelog.txt b/changelog.txt index ecbf4f2..38d0a8d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -405,3 +405,11 @@ - Raise the correct exception at file loading and show the error in the editor - Fix exception related to https://github.com/axios/axios/issues/811 + +## 7.0.1 + +2022-08-25 + +### Fix + +- Fix "send_file() got an unexpected keyword argument 'attachment_filename'" exception for new version of Flask