-
Notifications
You must be signed in to change notification settings - Fork 393
Python HL SDK: use IfNoneMatch to support conditional write (aka exclusive creation) #9309
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
Python HL SDK: use IfNoneMatch to support conditional write (aka exclusive creation) #9309
Conversation
32a69f9
to
e69ea94
Compare
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.
Looks good, had a small comment related to a check in the code.
Also, if you can open a follow-up issues:
- Refactor: the exception handling should use
api_exception_handler
with customer handler to address the specific if_none_match. This should align all the exceptions thrown based on the API to the SDK exception - Bug: it seems we have a resource leak while exception is thrown calling
close
and the upload/link throws an exception we continue to raise without closing the fd.
@@ -538,6 +538,8 @@ def _upload_raw(self) -> lakefs_sdk.ObjectStats: | |||
headers=headers, | |||
body=self._fd) | |||
|
|||
if self._mode.startswith("x") and resp.status == http.HTTPStatus.PRECONDITION_FAILED: |
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.
You can integrate this check into the _io_exception_handler to return the correct exception
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.
I want this exception to be raised only when If-None-Match
is set.
So, I don't think it makes sense to move this to _io_exception_handler()
. Adding a custom handler is an option, but that feels more complex.
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.
Looks good - one suggestion
if 'x' in mode and obj.exists(): # Requires explicit create | ||
raise ObjectExistsException | ||
|
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.
Discussed with @nopcoder and decided to reintroduce this check to fail early.
While this may impact performance, this check already existed, so this PR is not introducing any additional overhead.
…usive creation) Closes treeverse#7505. This replaces existing obj.exists() check with conditional writes with 'IfNoneMatch: *'. I have tried to maintain compat in terms of error raised, by raising `ObjectExistsError` on pre-condition failure.
ca0e8ae
to
b33478e
Compare
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.
LGTM
Change Description
Closes #7505.
This replaces existing
obj.exists()
check with conditional writes using 'IfNoneMatch: *'. I have tried to maintain compat in terms of error raised, by raisingObjectExistsError
on pre-condition failure.Testing Details
How were the changes tested?
There is an existing
test_object_upload_exists
that covers this. I have extended this test by parametrizing it withpre_sign=True|False
.Breaking Change?
Does this change break any existing functionality? (API, CLI, Clients)
No.
Additional info
Logs, outputs, screenshots of changes if applicable (CLI / GUI changes)
Contact Details
How can we get in touch with you if we need more info? (ex. [email protected])