Skip to content

fix(spec): report an error instead of panicking when a field default cannot be serialized - #3656

Open
compiler-segfault wants to merge 2 commits into
apache:mainfrom
compiler-segfault:fix/field-default-serialize-error
Open

compiler-segfault wants to merge 2 commits into
apache:mainfrom
compiler-segfault:fix/field-default-serialize-error

Conversation

@compiler-segfault

Copy link
Copy Markdown

Which issue does this PR close?

What changes are included in this PR?

NestedField is serialized through SerdeNestedField, and the From<NestedField> conversion used expect when a default value could not be converted to JSON. A field whose default does not fit its type therefore panicked inside serde_json::to_string, which is reachable from with_initial_default / with_write_default:

let field = NestedField::new(1, "f", Type::Primitive(PrimitiveType::Float), false)
    .with_initial_default(Literal::string("1e39"));
serde_json::to_string(&field); // panics

The conversion is now fallible (TryFrom<NestedField> for SerdeNestedField), and NestedField's hand-written Serialize passes that error through serde::ser::Error::custom, so serialization fails instead of aborting the process. Nothing else about the JSON shape changes.

Are these changes tested?

Two tests in spec::datatypes::tests cover the initial and the write default: both panic before the change and assert the serialization error afterwards. cargo test -p iceberg --lib passes (2141 passed, 1 ignored), and cargo clippy -p iceberg --all-targets -- -D warnings and cargo fmt are clean.

AI Disclosure

The change and this description were prepared with an AI coding agent (DeepSeek Harness, deepseek-flash). The diff and the test output were reviewed before submitting.

Uncertainty worth a reviewer's attention: whether reporting the conversion failure through serde::ser::Error::custom is the right surface for it, or whether Serialize should stay infallible and the type/validity check should move into with_initial_default / with_write_default instead.

…cannot be serialized

SerdeNestedField was built from NestedField with From and an expect,
so a default literal that does not fit the field type aborted the
process inside serde_json::to_string. Make the conversion fallible and
report it through serde::ser::Error::custom from a hand-written
Serialize impl.

Fixes apache#3627.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown

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.

Non-finite defaults cause panics during serde

2 participants