Transaction.upsert() pins the target branch with use_ref(branch), which sets a snapshot id, so TableScan.projection() resolves the schema recorded on that snapshot rather than the table's current schema. A schema-only update creates no data snapshot, so the branch tip can still carry the pre-update schema, and the matched rows are then read with a schema that no longer matches the input dataframe.
An added column surfaces as ValueError: Target schema's field names are not matching the table's field names in get_rows_to_update(). A renamed non-key column fails the same way, and a renamed join column fails earlier still, in has_duplicate_rows(), with KeyError.
The change is one call site in pyiceberg/table/__init__.py: the scan that reads the matched rows now projects the current table schema. File planning is untouched and still uses the pinned snapshot, so time-travel and ref scan semantics do not change. ArrowScan already binds the row filter against table_metadata.schema(), so the projection was the only part still tied to the snapshot's historical schema.
Are these changes tested?
Yes. Four cases added to tests/table/test_upsert.py, each of which fails on main:
test_upsert_after_adding_column
test_upsert_after_renaming_column
test_upsert_after_renaming_join_column
test_upsert_after_adding_column_in_transaction
uv run pytest tests/table/test_upsert.py -q → 27 passed.
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
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.
Closes #2467
Rationale for this change
Transaction.upsert() pins the target branch with use_ref(branch), which sets a snapshot id, so TableScan.projection() resolves the schema recorded on that snapshot rather than the table's current schema. A schema-only update creates no data snapshot, so the branch tip can still carry the pre-update schema, and the matched rows are then read with a schema that no longer matches the input dataframe.
An added column surfaces as ValueError: Target schema's field names are not matching the table's field names in get_rows_to_update(). A renamed non-key column fails the same way, and a renamed join column fails earlier still, in has_duplicate_rows(), with KeyError.
The change is one call site in pyiceberg/table/__init__.py: the scan that reads the matched rows now projects the current table schema. File planning is untouched and still uses the pinned snapshot, so time-travel and ref scan semantics do not change. ArrowScan already binds the row filter against table_metadata.schema(), so the projection was the only part still tied to the snapshot's historical schema.
Are these changes tested?
Yes. Four cases added to tests/table/test_upsert.py, each of which fails on main:
uv run pytest tests/table/test_upsert.py -q → 27 passed.
Are there any user-facing changes?
No.