Repository navigation
Check add_files duplicates against the target branch - #4347
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
add_files(branch=...) checked duplicates only against the current snapshot, so adding a file to a branch twice committed it again and doubled the rows. The check now also covers the target branch's snapshot, reading shared snapshots and manifests once. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
@kevinjqliu @laichunpongben could you take a look when you have a chance? It closes the branch gap in the |
AP24110011695
approved these changes
Nov 11, 2026
AP24110011695
left a comment
Contributor
There was a problem hiding this comment.
Verified locally (Windows, Python 3.12):
- The four new
tests/integration/test_add_files.pybranch tests pass on this branch across all three catalog fixtures (12 passed), and the two rejection tests fail on pre-change code (6 failed with main's source swapped in) — exactly the claimed fail-first behavior. The distinct-file-with-same-rows and referenced-only-by-main tests pass both ways, pinning that legitimate adds stay allowed and the main check is preserved. - Read the diff: the snapshot set dedupes by
snapshot_idand the manifest set bymanifest_path, so shared manifests are scanned once;snapshot_by_name(None)returnsNone(refs.get(None)), so the no-branch path collapses to exactly the old single-snapshot check. The executor/path_filtermachinery is unchanged — the only behavioral delta is the wider candidate set, which matches the description.
Nice find — the inconsistency #3287 describes was easy to hit on branch workflows, and the fix is minimal while keeping the shared-scan cost at one read.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
Transaction.add_files(..., branch=...)checks for already-referenced files only against the current snapshot (main), not against the target branch. Adding the same file to a branch twice is therefore not rejected, and reading the branch returns the file's rows twice:The second call succeeds, and the branch holds two live entries for
path. The same second call on main is rejected. #3287 describes this as a pre-existing inconsistency and preserved it.This change makes the check cover the target branch's snapshot as well as the current snapshot. The existing main check stays, and a file the branch already references is now rejected too. Snapshots and manifests shared by both are read once.
Related: #3287
Are these changes tested?
Yes. The tests are in
tests/integration/test_add_files.pyand run against the memory and SQL catalogs.test_add_files_to_branch_rejects_file_already_referenced_by_branchandtest_add_files_to_branch_rejects_file_added_earlier_in_transactionfail without this change (the second add is not rejected) and pass with it.test_add_files_to_branch_accepts_distinct_file_with_same_rowsadds a different path with the same rows and passes both ways.test_add_files_to_branch_rejects_file_referenced_only_by_mainpasses both ways and pins that files referenced by main are still rejected on a branch.Are there any user-facing changes?
Yes:
add_fileswith a non-mainbranchnow also rejects files that the branch already references. Files referenced by main are still rejected, and thecheck_duplicate_filesdocs mention the target branch.This pull request and its description were written by Isaac.