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

upload_fileobj sliently closes the passed file #3944

Closed
Foxicution opened this issue Nov 22, 2023 · 2 comments
Closed

upload_fileobj sliently closes the passed file #3944

Foxicution opened this issue Nov 22, 2023 · 2 comments
Assignees
Labels
duplicate This issue is a duplicate. s3

Comments

@Foxicution
Copy link

Describe the bug

When passing a file to boto3.client("s3").upload_fileobj the file gets closed silently. This causes, bugs (or requires reopening the file), to continue working on it.

Expected Behavior

File remains open after passing it to upload_fileobj.

Current Behavior

File gets closed and any further operation on the file produces and exception:
ValueError: I/O operation on closed file.

Reproduction Steps

To produce the exception because of upload_fileobj silently closing the file:

from io import BytesIO
import boto3
client = boto3.client("s3")
text = "Some text to upload"
with BytesIO(text.encode("utf-8")) as f:
    client.upload_fileobj(f, "bucket", "path/filename.txt")
    f.seek(0, 2) # or any other operation

If we swap the the operations around the exception goes away:

from io import BytesIO
import boto3
client = boto3.client("s3")
text = "Some text to upload"
with BytesIO(text.encode("utf-8")) as f:
    f.seek(0, 2) # or any other operation
    client.upload_fileobj(f, "bucket", "path/filename.txt")

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.28.38

Environment details (OS name and version, etc.)

NixOS 23.05

@Foxicution Foxicution added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2023
@tim-finnigan tim-finnigan self-assigned this Nov 24, 2023
@tim-finnigan
Copy link
Contributor

tim-finnigan commented Nov 24, 2023

Hi @Foxicution thanks for reaching out. We have received a few issues in the past related to this. It looks like the most recent one was mistakenly auto-closed: #3150. I just reopened it for tracking. The last comment I made there is still relevant:

...I brought this up for discussion with the team and they agreed that a short reference to this behavior could be added to the documentation if you want to create a PR. There is still some debate over whether the s3transfer issue should be considered a bug. But someone did share a workaround here in the comments.

I'll try raising this issue again with the team because I do see a lot of frustration in that related s3transfer issue (boto/s3transfer#80). But I'm going to close this as a duplicate and we can continue tracking the linked issues.

@tim-finnigan tim-finnigan added duplicate This issue is a duplicate. s3 and removed bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 24, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue is a duplicate. s3
Projects
None yet
Development

No branches or pull requests

2 participants