Skip to content

Commit

Permalink
Fix send_file exception for new version of Flask
Browse files Browse the repository at this point in the history
  • Loading branch information
andreax79 committed Aug 25, 2022
1 parent 576b253 commit f376c70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion airflow_code_editor/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.0.1
26 changes: 18 additions & 8 deletions airflow_code_editor/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f376c70

Please sign in to comment.