Skip to content

Conversation

skshetry
Copy link
Contributor

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 raising ObjectExistsError 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 with pre_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])

@skshetry skshetry force-pushed the fix/exclusive-file-create-mode branch 2 times, most recently from 32a69f9 to e69ea94 Compare July 17, 2025 13:52
@skshetry skshetry marked this pull request as draft July 17, 2025 14:12
@skshetry skshetry marked this pull request as ready for review July 21, 2025 04:40
@itaiad200 itaiad200 requested review from nopcoder and N-o-Z July 22, 2025 08:07
Copy link
Contributor

@nopcoder nopcoder left a 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:
Copy link
Member

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

Copy link
Contributor Author

@skshetry skshetry Jul 25, 2025

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.

Copy link
Member

@N-o-Z N-o-Z left a 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

Comment on lines 402 to 404
if 'x' in mode and obj.exists(): # Requires explicit create
raise ObjectExistsException

Copy link
Contributor Author

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.
@skshetry skshetry force-pushed the fix/exclusive-file-create-mode branch from ca0e8ae to b33478e Compare August 5, 2025 09:00
@skshetry skshetry requested a review from nopcoder August 5, 2025 09:01
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nopcoder nopcoder added include-changelog PR description should be included in next release changelog python-wrapper labels Aug 5, 2025
@nopcoder nopcoder merged commit 1e61a4d into treeverse:master Aug 5, 2025
42 of 44 checks passed
@skshetry skshetry deleted the fix/exclusive-file-create-mode branch August 5, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog python-wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python high level SDK: support mode="x"
3 participants