Repository navigation
Preserve falsy non-empty values in property helper functions - #4489
Merged
Merged
Conversation
property_as_int(), property_as_float(), and get_first_property_value() used truthiness checks (`if value := properties.get(...)`), causing explicitly configured falsy values such as 0, 0.0, or False to be silently ignored and replaced by defaults or fallback keys. Match property_as_bool() semantics by checking `is not None and value != ""` so explicit zero/False values are preserved while None and empty strings continue to fall back to defaults or subsequent keys, and widen property_as_int and property_as_float to accept Mapping[str, Any] (matching Properties callers).
Fokko
approved these changes
Nov 30, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Thanks @xgbtxy, this moves the helpers closer to Java's PropertyUtil, which only checks value != null. Treating "" as unset still differs from Java, but that matches property_as_bool and merge_config. I'll open a follow-up issue for the small consistency cleanups.
8 tasks
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
property_as_int(),property_as_float(), andget_first_property_value()inpyiceberg/utils/properties.pychecked truthiness (if value := properties.get(...)) rather than checking forNoneor"". Because0,0.0, andFalseare falsy in Python, passing an explicit numeric zero or booleanFalseviaProperties(for examplecommit.retry.num-retries=0,rest.sigv4-max-retries=0,write.parquet.compression-level=0, orresidual-cache-max-size=0) silently fell back to the default value or a later fallback key.This change aligns
property_as_int(),property_as_float(), andget_first_property_value()withproperty_as_bool()(checkingis not None and ... != ""so empty strings andNoneremain treated as unset while valid falsy values are honored, consistent with the discussion in #3713 / #3801 andmerge_configinpyiceberg/utils/config.py). It also widens thepropertiesparameter type ofproperty_as_int()andproperty_as_float()fromdict[str, str]toMapping[str, Any]to match callers passingProperties(dict[str, Any]) ordict[str, str].Are these changes tested?
Yes. Added regression tests in
tests/utils/test_properties.py:test_property_as_int_preserves_zero_and_treats_empty_as_unsettest_property_as_float_preserves_zero_and_treats_empty_as_unsettest_get_first_property_value_preserves_falsy_non_empty_valuesConfirmed all 3 new tests fail prior to the fix (
3 failed) and all 13 tests intests/utils/test_properties.pypass after the fix (13 passed), along withruff,ty,mypy, andcodespellchecks.Are there any user-facing changes?
Yes. Passing explicit falsy non-empty property values (
0,0.0,False) inPropertiestoproperty_as_int(),property_as_float(), orget_first_property_value()now preserves those values instead of silently falling back to defaults or secondary keys. Empty strings ("") andNonecontinue to be treated as unset.