Skip to content

Use HeadObject instead of GetObject for S3 metadata (#565)#567

Merged
pjbull merged 1 commit into
masterfrom
1390-live-tests
Jun 10, 2026
Merged

Use HeadObject instead of GetObject for S3 metadata (#565)#567
pjbull merged 1 commit into
masterfrom
1390-live-tests

Conversation

@pjbull

@pjbull pjbull commented Jun 10, 2026

Copy link
Copy Markdown
Member

Live tests for #565

  • Use HeadObject instead of GetObject for S3 metadata

S3Client._get_metadata read object metadata via ObjectSummary.get() (a GetObject), which issues a full object read and leaves an unread response stream instead of returning the connection to the pool. Switch to head_object, which reads only the metadata and keeps Content-Length on S3-compatible gateways that drop it from GetObject responses, while bringing S3 in line with the other backends.

Since head_object returns no body, a missing key surfaces as a generic 404 ClientError rather than NoSuchKey, so S3Path.stat now translates a 404 to NoStatError and lets other errors (e.g. 403) propagate. Updates the S3 test mock and adds regression tests.

Closes #564

* Use HeadObject instead of GetObject for S3 metadata

S3Client._get_metadata read object metadata via ObjectSummary.get()
(a GetObject), which issues a full object read and leaves an unread
response stream instead of returning the connection to the pool. Switch
to head_object, which reads only the metadata and keeps Content-Length
on S3-compatible gateways that drop it from GetObject responses, while
bringing S3 in line with the other backends.

Since head_object returns no body, a missing key surfaces as a generic
404 ClientError rather than NoSuchKey, so S3Path.stat now translates a
404 to NoStatError and lets other errors (e.g. 403) propagate. Updates
the S3 test mock and adds regression tests.

Closes #564

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* add PR number

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot temporarily deployed to pull request June 10, 2026 22:44 Inactive
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.9%. Comparing base (27d749e) to head (49ffa58).

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #567   +/-   ##
======================================
  Coverage    93.9%   93.9%           
======================================
  Files          28      28           
  Lines        2222    2226    +4     
======================================
+ Hits         2088    2092    +4     
  Misses        134     134           
Files with missing lines Coverage Δ
cloudpathlib/s3/s3client.py 94.3% <100.0%> (ø)
cloudpathlib/s3/s3path.py 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pjbull pjbull merged commit b0e462e into master Jun 10, 2026
28 checks passed
@pjbull pjbull deleted the 1390-live-tests branch June 10, 2026 23:17
@pjbull

pjbull commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

Thanks @mattijsdp !

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3Client._get_metadata uses GetObject where HeadObject would do

2 participants