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

[16.0][FIX] attachment_zipped_download: create temporary file to stream #430

Merged
merged 1 commit into from
Feb 22, 2024
Merged

[16.0][FIX] attachment_zipped_download: create temporary file to stream #430

merged 1 commit into from
Feb 22, 2024

Conversation

len-foss
Copy link
Contributor

@len-foss len-foss commented Sep 8, 2023

Despite accurately getting the size from the BytesIO object, Werkzeug doesn't stream its content.
This updates the code to use Odoo's http.Stream class.

Fixes #406

Before the fix, 0 bytes would be transferred.
@pedrobaeza pedrobaeza changed the title [FIX] attachment_zipped_download: create temporary file to stream [16.0][FIX] attachment_zipped_download: create temporary file to stream Sep 8, 2023
@pedrobaeza pedrobaeza added this to the 16.0 milestone Sep 8, 2023
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working

Copy link

github-actions bot commented Jan 7, 2024

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jan 7, 2024
@len-foss
Copy link
Contributor Author

len-foss commented Jan 8, 2024

Is there any reason not to merge this?

Copy link
Contributor

@petrus-v petrus-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good but I've the feeling it's a shame here, we have a new class to manage stream and we are not using it...

_create_temp_zip() return a BytesIO the getvalue() return the raw bytes which is then transform again as a bytesIO by the htpp.Stream class. In a large zip file this could be a lot of memory.

The title told us that it create a temporary file to stream but I don't think it's the case with this change. I've the feeling it would be probably better to do that, change a bit _create_temp_zip to write a temporary file and use Stream with type="path"

As far i understand this mainly avoid to use a deprecated method that I won't be opposed, the improvement can come later !

@len-foss
Copy link
Contributor Author

len-foss commented Jan 9, 2024

The history is lost because I force-pushed the branch (a long time ago so it was pruned); the first version used fo = tempfile.NamedTemporaryFile(); fo.write(out_file.getvalue()) and passed fo as the stream argument.
What bothered me is that in any case we have a call to getvalue.
If there's a better way we can go for it, I just didn't find one.

@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jan 14, 2024
Copy link

@aleuffre aleuffre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

@pedrobaeza
Copy link
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-430-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit e7aef87 into OCA:16.0 Feb 22, 2024
4 of 5 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at dafab10. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[16.0] attachment_zipped_download: Incomplete file
5 participants