Skip to content

Commit f376c70

Browse files
committed
Fix send_file exception for new version of Flask
1 parent 576b253 commit f376c70

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

airflow_code_editor/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.0.0
1+
7.0.1

airflow_code_editor/fs.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,28 @@ def send_file(self, as_attachment: bool):
200200
raise FileNotFoundError(errno.ENOENT, 'File not found', self.path)
201201
elif self.root_fs.hassyspath(self.path):
202202
# Local filesystem
203-
return send_file(
204-
self.root_fs.getsyspath(self.path),
205-
as_attachment=as_attachment,
206-
attachment_filename=self.name if as_attachment else None,
207-
)
203+
if as_attachment:
204+
# Send file as attachment (set Content-Disposition: attachment header)
205+
try:
206+
# flask >= 2.0 - download_name replaces the attachment_filename
207+
return send_file(
208+
self.root_fs.getsyspath(self.path),
209+
as_attachment=True,
210+
download_name=self.name,
211+
)
212+
except TypeError:
213+
return send_file(
214+
self.root_fs.getsyspath(self.path),
215+
as_attachment=True,
216+
)
217+
else:
218+
return send_file(self.root_fs.getsyspath(self.path))
208219
else:
209220
# Other filesystems
210221
response = Response(stream_with_context(self.read_file_chunks()))
211222
if as_attachment:
212-
response.headers[
213-
'Content-Disposition'
214-
] = 'attachment;filename={}'.format(self.name)
223+
content_disposition = 'attachment;filename={}'.format(self.name)
224+
response.headers['Content-Disposition'] = content_disposition
215225
return response
216226

217227
def write_file(self, data: Union[str, bytes], is_text: bool) -> None:

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,11 @@
405405

406406
- Raise the correct exception at file loading and show the error in the editor
407407
- Fix exception related to https://github.com/axios/axios/issues/811
408+
409+
## 7.0.1
410+
411+
2022-08-25
412+
413+
### Fix
414+
415+
- Fix "send_file() got an unexpected keyword argument 'attachment_filename'" exception for new version of Flask

0 commit comments

Comments
 (0)