Skip to content

Conversation

@somasays
Copy link
Contributor

@somasays somasays commented Dec 8, 2025

Summary

Test plan

  • All 3032 unit tests pass
  • Lint passes
  • New tests cover: updating list element required, updating map value required

Closes #2786

… values

Closes apache#2786

The `update_schema().update_column()` method was not updating the
`required` property for list elements or map values. The `_ApplyChanges`
visitor's `list()` and `map()` methods always used the original
`element_required` and `value_required` values without checking for
updates in `self._updates`.

This fix modifies both methods to check `self._updates` for the
element/value field ID and use the updated `required` value if present.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug where update_schema().update_column() was not properly updating the required property for list elements and map values. The fix modifies the _ApplyChanges visitor class to check for updates to these nested fields and apply the required property accordingly.

Changes:

  • Modified _ApplyChanges.list() method to check self._updates for element's required property updates
  • Modified _ApplyChanges.map() method to check self._updates for value's required property updates
  • Added comprehensive unit tests for both list element and map value required property updates

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyiceberg/table/update/schema.py Fixed list() and map() methods to properly apply required property updates from self._updates dictionary
tests/table/test_init.py Added two new unit tests to verify list element and map value required property can be updated

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM, this fix allows us to change nullability

would be nice to include a few more tests, i can add a follow up PR


# Update element to required
update2 = UpdateSchema(transaction=table_v2.transaction(), schema=schema_with_list)
update2._allow_incompatible_changes = True # Allow optional -> required
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding this

optional -> required is incompatible and thus requires the flag

if not self._allow_incompatible_changes and required:
raise ValueError(f"Cannot change column nullability: {name}: optional -> required")

@kevinjqliu kevinjqliu merged commit af17de8 into apache:main Jan 25, 2026
14 checks passed
Fokko pushed a commit that referenced this pull request Jan 25, 2026
<!--
Thanks for opening a pull request!
-->

<!-- In the case this PR will resolve an issue, please replace
${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
<!-- Closes #${GITHUB_ISSUE_ID} -->

# Rationale for this change
Follow up to #2798
More test coverages 

## Are these changes tested?

## Are there any user-facing changes?

<!-- In the case of user-facing changes, please add the changelog label.
-->

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

update_schema().update_column() does not update required property for list elements

2 participants