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

S3.Client.head_object() raises S3.Client.exceptions.ClientError instead of the documented S3.Client.exceptions.NoSuchKey #3988

Closed
valentinoli opened this issue Jan 12, 2024 · 2 comments
Assignees
Labels
bug This issue is a confirmed bug. s3

Comments

@valentinoli
Copy link

Describe the bug

When calling S3.Client.head_object() and the provided key is not found in the S3 bucket, the function does not raise the expected error type.

Expected Behavior

I expected the function to raise S3.Client.exceptions.NoSuchKey as per the docs, and also consistent with the behavior of S3.Client.get_object().

Current Behavior

The function raises S3.Client.exceptions.ClientError.

Reproduction Steps

session = boto3.Session()
client = session.client("s3")
client.head_object(Bucket="MyBucket", Key="NonExistingKey")

Possible Solution

Raise the expected error type.

Additional Information/Context

No response

SDK version used

boto3==1.28.83 and botocore==1.31.83

Environment details (OS name and version, etc.)

WSL 2 (Ubuntu 20.04)

@valentinoli valentinoli added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2024
@tim-finnigan tim-finnigan self-assigned this May 9, 2024
@tim-finnigan tim-finnigan added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label May 9, 2024
@tim-finnigan
Copy link
Contributor

Thanks for reaching out and your patience here. Related issues have come up here a few times before, for example #2499. Both the HeadObject and HeadBucket APIs return 404 errors if the object or bucket does not exist. And as noted in the documentation:

A HEAD request has the same options as a GET operation on an object. The response is identical to the GET response except that there is no response body. Because of this, if the HEAD request generates an error, it returns a generic code, such as 400 Bad Request, 403 Forbidden, 404 Not Found, 405 Method Not Allowed, 412 Precondition Failed, or 304 Not Modified. It's not possible to retrieve the exact exception of these error codes.

So this is the behavior of the underlying S3 API and therefore not something that will be addressed in Boto3. As mentioned in previous issues it would be a breaking change to update the model. But please use the Provide feedback at the bottom of API documentation pages to send any additional feedback directly to the S3 team.

@tim-finnigan tim-finnigan closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
@tim-finnigan tim-finnigan added s3 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels May 9, 2024
Copy link

github-actions bot commented May 9, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

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

No branches or pull requests

2 participants