Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change in 1.0.0 to add pathlib support for .save() breaks usage of io.BytesIO #1733

Closed
acaos opened this issue Feb 15, 2020 · 3 comments · Fixed by #1734
Closed

Change in 1.0.0 to add pathlib support for .save() breaks usage of io.BytesIO #1733

acaos opened this issue Feb 15, 2020 · 3 comments · Fixed by #1734
Labels
Milestone

Comments

@acaos
Copy link

@acaos acaos commented Feb 15, 2020

Versions

  • Python 3.7
  • Werkzeug 1.0.0 (from PyPI)

Report

The addition of pathlib support to .save() from #1654 breaks the the ability to pass io.BytesIO objects to .save().

Previous behavior: Saving to an io.BytesIO object worked as expected.
Behavior in 1.0.0: An exception is thrown in fspath().

  File "/app/main.py", line 310, in extract_metadata
    files['metadata'].save(metadata_io)
  File "/app/.venv/lib/python3.7/site-packages/werkzeug/datastructures.py", line 3061, in save
    dst = fspath(dst)
TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
@Vermeille

This comment has been minimized.

@Vermeille
Copy link

@Vermeille Vermeille commented Feb 17, 2020

For now I'm using this workaround

# until https://github.com/pallets/werkzeug/issues/1733 is fixed
buf = io.BytesIO()
#request.files['photo'].save(buf)
from shutil import copyfileobj
copyfileobj(request.files['photo'].stream, buf, 16384)

@davidism davidism added this to the 1.0.1 milestone Feb 17, 2020
@davidism davidism added the bug label Feb 17, 2020
@davidism
Copy link
Member

@davidism davidism commented Feb 17, 2020

Looks like we need to do some shuffling with the order we check the types and do the conversion, in order to continue to support file-like objects. Scheduled for 1.0.1, PRs welcome if anyone can work on a fix.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants