Skip to content

Conversation

@skshetry
Copy link
Contributor

Change Description

Background

This PR addresses GitHub issue #8200 where users requested the ability to create tags automatically during transactions, eliminating the need to manually retrieve commit SHA and create tags separately.

Bug Fix

N/A - This is a new feature.

New Feature

Added optional tag parameter to Branch.transact() method for automatic tag creation after successful transaction completion.

Usage:

with branch.transact(commit_message='update', tag='v1.0.0') as tx:
    tx.object('file.txt').upload('data')
# Tag 'v1.0.0' created automatically on merge commit

Key behaviors:

  • Tag created only on transaction success
  • Tag accessible via tx.tag attribute during transaction

Testing Details

  • All integration tests pass (79/79, excluding known unrelated failure)
  • New integration test validates tag functionality
  • Perfect pylint scores (10.00/10)
  • All existing functionality remains unchanged

Breaking Change?

No. This is a backward-compatible addition - existing transaction code works unchanged.

Additional info

Files modified:

  • lakefs/branch.py: Added tag parameter and creation logic
  • tests/integration/test_branch.py: Added tag functionality test

Contact Details

Available via GitHub for questions.

@N-o-Z N-o-Z self-requested a review July 23, 2025 13:13
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.

Great addition!

Added some comments, mainly about setter behavior and tests

@skshetry skshetry force-pushed the feat/python-transaction-tag-parameter branch 3 times, most recently from 3d07bcf to 3a5cf8e Compare July 23, 2025 15:17
Add optional tag parameter to automatically create tags after successful
transaction completion, eliminating manual commit SHA retrieval.

Usage:

```py
  with branch.transact(commit_message='update', tag='v1.0.0') as tx:
      tx.object('file.txt').upload('data')
  # Tag 'v1.0.0' created on merge commit
```

- Tag created only on transaction success (fail-fast validation)
- Empty tag names treated as None
- Tag accessible via tx.tag attribute

Closes: treeverse#8200
@skshetry skshetry force-pushed the feat/python-transaction-tag-parameter branch from 3a5cf8e to 80c80f9 Compare July 23, 2025 15:18
initial_commit = test_branch.commit("initial commit")
repo.tag("v1.0.0").create(initial_commit)

with expect_exception_context(ConflictException, "tag already exists"):
Copy link
Contributor Author

@skshetry skshetry Jul 23, 2025

Choose a reason for hiding this comment

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

I wonder why we use this custom function instead of using pytest.raises(..., match=...).

This is equivalent to:

Suggested change
with expect_exception_context(ConflictException, "tag already exists"):
with pytest.raises(ConflictException, match="tag already exists"):

Copy link
Contributor

@itaiad200 itaiad200 left a comment

Choose a reason for hiding this comment

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

wip

@skshetry skshetry requested review from N-o-Z and itaiad200 August 5, 2025 08:27
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.

LGTM with one comment.
In addition, please refrain from force pushing or rebasing your branch while review is in progress.
It makes the review process longer and more difficult

Comment on lines +248 to +253
with test_branch.transact(commit_message="my transaction with existing tag", tag="v1.0.0") as tx:
upload_data(tx, path_and_data)

# Verify transaction branch was deleted
with expect_exception_context(NotFoundException):
repo.branch(tx.id).get_commit()
Copy link
Member

Choose a reason for hiding this comment

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

Test should not assume transaction successful.
Need to verify data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was supposed to be just a sanity check, as some other tests likely verify the data.

Copy link
Member

Choose a reason for hiding this comment

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

There are no old tests that verify the data upon failure to tag the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Failure to create a tag does not fail the transaction as it happens after the fact.

Copy link
Member

Choose a reason for hiding this comment

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

This is you speaking as a developer who read the code.
The test is not supposed to assume that.
If we assumed our code does exactly what we want we wouldn't be writing tests.

Copy link
Contributor Author

@skshetry skshetry Aug 7, 2025

Choose a reason for hiding this comment

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

Would you be okay with testing that the branch moved to a new commit (i.e is not the initial_commit)? Would that be enough to verify the transaction was successful?

Or, do you think we should verify the data?

Copy link
Member

Choose a reason for hiding this comment

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

I think checking the commit should be sufficient

@skshetry
Copy link
Contributor Author

skshetry commented Aug 7, 2025

LGTM with one comment.
In addition, please refrain from force pushing or rebasing your branch while review is in progress.
It makes the review process longer and more difficult

If you are not aware, you may find the 'Compare' button above on GitHub useful for reviewing these changes.

Sorry, it looks like GitHub hides previous pushes nowadays (seems to have happened somewhere around mid 2022), and only shows you latest pushes. 🤦🏽

@itaiad200 itaiad200 dismissed their stale review September 2, 2025 15:34

Don't have time to review

@N-o-Z N-o-Z merged commit 3a3ef32 into treeverse:master Sep 2, 2025
1 check passed
@skshetry skshetry deleted the feat/python-transaction-tag-parameter branch September 2, 2025 15:43
@skshetry
Copy link
Contributor Author

skshetry commented Sep 3, 2025

Hey @N-o-Z, sorry about leaving this hanging, without any updates.
I'll address #9334 (comment) this week.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants