Skip to content

Test add_files duplicate checks on branches - #4347

Open
rahulsmahadev wants to merge 3 commits into
apache:mainfrom
rahulsmahadev:rahul/add-files-branch-duplicate-check
Open

rahulsmahadev wants to merge 3 commits into
apache:mainfrom
rahulsmahadev:rahul/add-files-branch-duplicate-check

Conversation

@rahulsmahadev

@rahulsmahadev rahulsmahadev commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

#4446 made the add_files duplicate check use the target branch, which fixes the case this PR was opened for: adding the same file to a branch twice. Main has no tests for the check on a branch yet, so this PR now only adds them.

Are these changes tested?

Yes, this PR only adds tests in tests/integration/test_add_files.py, run against the memory and SQL catalogs:

  • test_add_files_to_branch_rejects_file_already_referenced_by_branch
  • test_add_files_to_branch_rejects_file_added_earlier_in_transaction
  • test_add_files_to_branch_accepts_distinct_file_with_same_rows

The first two fail when the check reads the current snapshot instead of the branch (the code before #4446) and pass on main.

Are there any user-facing changes?

No.

Related: #3287, #4446

This pull request and its description were written by Isaac.

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>
@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

@kevinjqliu @laichunpongben could you take a look when you have a chance? It closes the branch gap in the add_files duplicate check that #3287 called out.

@AP24110011695 AP24110011695 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified locally (Windows, Python 3.12):

  • The four new tests/integration/test_add_files.py branch 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_id and the manifest set by manifest_path, so shared manifests are scanned once; snapshot_by_name(None) returns None (refs.get(None)), so the no-branch path collapses to exactly the old single-snapshot check. The executor/path_filter machinery 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.

@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

Gentle ping @kevinjqliu: CI is green and it has one approval. Could you take a look when you have a moment? Thanks!

@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

@ebyhr could you take a look when you have a chance? Thanks!

@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

@Fokko could you take a look when you have a chance? It has two approvals and CI is green. Thanks!

rahulsmahadev and others added 2 commits November 23, 2026 05:42
apache#4446 made the duplicate check use the target branch, so the code change is no
longer needed. Keep the branch tests as coverage for it, and drop the test for
a file referenced only by main, which apache#4446 allows.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@rahulsmahadev rahulsmahadev changed the title Check add_files duplicates against the target branch Test add_files duplicate checks on branches Nov 23, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants