-
Notifications
You must be signed in to change notification settings - Fork 116
Implement exclusive create for open("xb"), put_file() and pipe_file() #1009
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,9 @@ class S3ClientError: | |
| as properties, along with :attr:`os_error`, the equivalent standard | ||
| Python exception. The error is mapped by its S3 error code first, then | ||
| by its HTTP status code; if neither is recognized, a generic ``OSError`` | ||
| with the original error message is used. | ||
| with the original error message is used. A ``PreconditionFailed`` error | ||
| of an ``If-None-Match`` condition, from a write that must not replace an | ||
| existing object, is mapped to ``FileExistsError``. | ||
|
|
||
| Example: | ||
| >>> try: | ||
|
|
@@ -105,11 +107,15 @@ def __init__(self, error: botocore.exceptions.ClientError) -> None: | |
| error_info = error.response.get("Error", {}) | ||
| self._code: str = str(error_info.get("Code", "")) | ||
| self._message: str = str(error_info.get("Message", error)) | ||
| self._condition: str = str(error_info.get("Condition", "")) | ||
| status_code = error.response.get("ResponseMetadata", {}).get("HTTPStatusCode") | ||
| self._http_status_code: int | None = int(status_code) if status_code is not None else None | ||
| self._os_error: OSError = self._translate() | ||
|
|
||
| def _translate(self) -> OSError: | ||
| if self._code == "PreconditionFailed" and self._condition == "If-None-Match": | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round 2 (claims, callers, operations) — FINDINGS (2, repaired in 08bcff5 and the PR body) Base Claims checked:
Findings and repairs:
|
||
| # A conditional write (IfNoneMatch="*") found an existing object. | ||
| return FileExistsError(self._message) | ||
| exception = self._ERROR_CODE_TO_EXCEPTION.get(self._code) | ||
| if exception: | ||
| return exception(self._message) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round 1 (behavior and implementation) — FINDINGS (1, resolved without code change)
Base
28826be7d37983cb54050e849b32a4fe2331ea7d, headbf5743b6d3fca17a1d37ce716cad6312a858044c.Covered:
S3File.__init__x-mode check andIfNoneMatchrouting through_get_request_kwargsto PutObject / CompleteMultipartUpload /touch()(not CreateMultipartUpload / UploadPart; checked against the botocore input shapes);commit()failure paths (412 on PutObject; 412 on completion →_finish_multipart_uploadabort,multipart_uploadreset);pipe_file()single-request and buffered paths;put_file()sync, async, and async in-transaction;S3ClientErrortranslation (If-None-Match vs If-Match vs no condition); fsspecTransaction.complete()on a failed commit (re-queues and discards the rest, clears_intrans); fsspecput()/_put()forwardingmodethrough**kwargs; executor on aFileExistsErrorat open (created lazily, as on the read path'sFileNotFoundError); botocore floor 1.41.2 hasIfNoneMatchon both operations.Finding: the up-front
exists()propagatesPermissionErrorfor a key that HeadObject denies (pyathena/filesystem/s3.py:917-923catches onlyFileNotFoundError), so a PutObject-only principal cannot usexb/create. Pre-existing forpipe_file(mode=\"create\"). Maintainer chose to keep it (permission errors are not hidden); recorded in the PR body.Tests: the regression tests fail on the original code (15 cases), and the live test exercises the real 412 path. The async
test_put_file_modeavoids the shared internalS3FileSysteminstance (pre-existing test pollution, noted in the PR body).