Skip to content

Preserve falsy non-empty values in property helper functions - #4489

Open
xgbtxy wants to merge 1 commit into
apache:mainfrom
xgbtxy:fix/properties-preserve-falsy-values
Open

xgbtxy wants to merge 1 commit into
apache:mainfrom
xgbtxy:fix/properties-preserve-falsy-values

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Nov 25, 2026

Copy link
Copy Markdown

Rationale for this change

property_as_int(), property_as_float(), and get_first_property_value() in pyiceberg/utils/properties.py checked truthiness (if value := properties.get(...)) rather than checking for None or "". Because 0, 0.0, and False are falsy in Python, passing an explicit numeric zero or boolean False via Properties (for example commit.retry.num-retries=0, rest.sigv4-max-retries=0, write.parquet.compression-level=0, or residual-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(), and get_first_property_value() with property_as_bool() (checking is not None and ... != "" so empty strings and None remain treated as unset while valid falsy values are honored, consistent with the discussion in #3713 / #3801 and merge_config in pyiceberg/utils/config.py). It also widens the properties parameter type of property_as_int() and property_as_float() from dict[str, str] to Mapping[str, Any] to match callers passing Properties (dict[str, Any]) or dict[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_unset
  • test_property_as_float_preserves_zero_and_treats_empty_as_unset
  • test_get_first_property_value_preserves_falsy_non_empty_values

Confirmed all 3 new tests fail prior to the fix (3 failed) and all 13 tests in tests/utils/test_properties.py pass after the fix (13 passed), along with ruff, ty, mypy, and codespell checks.

Are there any user-facing changes?

Yes. Passing explicit falsy non-empty property values (0, 0.0, False) in Properties to property_as_int(), property_as_float(), or get_first_property_value() now preserves those values instead of silently falling back to defaults or secondary keys. Empty strings ("") and None continue to be treated as unset.

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).
Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:54

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

2 participants