fix(udf): replace state during JSON decoding - #1626
Open
fallintoplace wants to merge 3 commits into
Open
Conversation
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.
Summary
Make UDF JSON decoding replace receiver state instead of merging into it.
Problem
Several UDF
UnmarshalJSONimplementations 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
definitionscan pass validation using retained definitions, and the lazy definition index can remain stale. Exported nested values such asParameter,DefinitionVersion,Definition, andDefinitionLogEntryalso 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.