Skip to content

fix(udf): replace state during JSON decoding - #1626

Open
fallintoplace wants to merge 3 commits into
apache:mainfrom
fallintoplace:fix/udf-replace-unmarshal-state
Open

fix(udf): replace state during JSON decoding#1626
fallintoplace wants to merge 3 commits into
apache:mainfrom
fallintoplace:fix/udf-replace-unmarshal-state

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Make UDF JSON decoding replace receiver state instead of merging into it.

Problem

Several UDF UnmarshalJSON implementations decode through aliases of their existing receivers. Go leaves struct fields unchanged when they are absent from a new JSON document, so reusing a receiver can retain values from an earlier decode.

At the metadata level, a malformed document without definitions can pass validation using retained definitions, and the lazy definition index can remain stale. Exported nested values such as Parameter, DefinitionVersion, Definition, and DefinitionLogEntry also retain omitted optional fields when decoded directly.

Fix

Decode each value into fresh state and assign it to the receiver only after decoding succeeds. Top-level metadata is also validated before assignment, then initializes its definition index from the replacement state.

Tests

Added receiver-reuse coverage for top-level metadata and exported nested values. The tests verify omitted optional fields are cleared, cached indexes are replaced, and failed metadata decoding does not partially overwrite the last valid state.

go test ./udf -count=1

@fallintoplace fallintoplace changed the title fix(udf): replace metadata state during decoding fix(udf): replace state during JSON decoding Aug 1, 2026
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.

1 participant