Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

util: use the uploaded werkzeug.FileStorage class directly #29

Merged

Conversation

abrasive
Copy link
Contributor

@abrasive abrasive commented Aug 21, 2019

In newer versions of Werkzeug the uploaded file's stream is a
SpooledTemporaryFile. That class doesn't implement the .seekable method,
which is called by the Python zipfile library, and everything falls
over.

I experienced this error with Python 3.7.4 and package versions:

certifi==2019.6.16
Click==7.0
conf==0.4.1
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
natsort==6.0.0
pipenv==2018.11.26
six==1.12.0
virtualenv==16.7.3
virtualenv-clone==0..5.3
Werkzeug==0.15.5

This patch avoids the issue by using the FileStorage class directly; as
of Werkzeug 0.15 it proxies this method correctly to whatever
object is backing the SpooledTemporaryFile.
Relevant GH issue: pallets/werkzeug#1344

This may be the cause of #27.

@abrasive
Copy link
Contributor Author

Apologies, I didn't update the tests, I'll go and fix that.

@abrasive abrasive force-pushed the fix-SpooledTemporaryFile-seekable branch from bd7ba57 to f6a48f2 Compare August 21, 2019 11:26
@abrasive
Copy link
Contributor Author

Fixed the tests. Thanks for setting up such a nice test suite!

@rgalanakis
Copy link
Owner

I need to get this fixed up and running locally, but are the test failures due to your changes?
Also how backwards-compatible is this? I am about ready to remove 2x support but would like to keep some 3x compat. I can also write a shim (it'd help to know what versions I need old compat for though).
Thank you for this, changes look excellent!

@rgalanakis
Copy link
Owner

Just saw #30 , answered my questions

@rgalanakis
Copy link
Owner

Please rebase to get tests passing, and I'll merge.

In newer versions of Werkzeug the uploaded file's stream is a
SpooledTemporaryFile. That class doesn't implement the .seekable method,
which is called by the Python zipfile library, and everything falls
over.

This patch avoids the issue by using the FileStorage class directly; as
of Werkzeug 0.15 it proxies this method correctly to whatever
object is backing the SpooledTemporaryFile. (At least according to the
relevant GH issue: pallets/werkzeug#1344 ).
@abrasive abrasive force-pushed the fix-SpooledTemporaryFile-seekable branch from f6a48f2 to 0f9b513 Compare August 22, 2019 03:47
@abrasive
Copy link
Contributor Author

Good to go. Cheers!

@rgalanakis rgalanakis merged commit d309772 into rgalanakis:master Aug 22, 2019
@rgalanakis rgalanakis mentioned this pull request Apr 15, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants