Skip to content

fix(converter): handle null/empty JSON payloads and matching path+JSON list keys - #570

Open
steiler wants to merge 2 commits into
mainfrom
fix/gnmi-converter-generic-fixes
Open

steiler wants to merge 2 commits into
mainfrom
fix/gnmi-converter-generic-fixes

Conversation

@steiler

@steiler steiler commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes three standalone JSON / JSON_IETF handling bugs in pkg/utils/converter.go (uncovered via live gNMI Get/Subscribe probe responses in #557):

  1. JSON null (json_val: "null" / json_ietf_val: "null" and nested null members):

    • Previously, Decode(&v) yielded v == nil, causing ExpandContainerValue to hit reflect.TypeOf(jv).String() and panic on nil, while SchemaElem_Field passed nil into sdcpb.ConvertJsonValueToTv (panicking on decimal64, fabricating "<nil>" on enumeration/bits, and silently fabricating 0/false on numeric/boolean leaves).
    • Per RFC 7951 §§ 5.5 & 6.9 (type empty is [null], while bare null represents an absent member) and gNMI § 2.3.1, decoded nil is now treated as absent/no-op on top-level containers, top-level fields, and known nested members, while preserving [null] for empty leaves and EmptyVal for child presence containers whose JSON object contains only null/state children. Also replaces reflect.TypeOf(...).String() / .Name() with nil-safe %T.
  2. Empty or whitespace-only JSON payloads (json_val: ""):

    • Unconfigured containers returning zero-length or whitespace-only json_val / json_ietf_val previously failed json.Decoder.Decode with io.EOF (causing GetSync / StreamSync to drop the notification) or leaked an unexpanded TypedValue when JsonVal was nil on a field path.
    • decodeJSONValue now treats empty/whitespace-only JSON byte slices as an empty update (nil, nil).
  3. List keys present in both upd.Path and the JSON object:

    • A gNMI Get on a keyed list entry (gNMI §§ 2.2.2 & 2.3.1, RFC 7950 § 7.8.2, RFC 7951 § 5.4) carries the key in PathElem.key and repeats the key leaf inside the serialized JSON entry object. ExpandContainerValue previously rejected any overlap unconditionally (key %q is present in both the path and JSON value).
    • resolveListKey reconciles bare (<key>), RFC 7951 module-qualified (<module>:<key>), and path-supplied keys—stripping valid module/prefix qualifiers on both direct identityref and leafref-to-identityref keys—accepting matching normalized values and returning an error when values or explicit qualifiers conflict.

Testing

  • Added unit tests in pkg/utils/converter_test.go covering container/field/nested null, RFC 7951 [null] on empty, child presence containers with null children, nil/empty/whitespace json_val & json_ietf_val, matching vs. conflicting path+JSON list keys (array, object, and leafref → identityref module qualifiers), and multi-update ExpandUpdates batches.
  • go test -race ./...
  • golangci-lint run ./pkg/utils/...

…N list keys

Handle three generic JSON/JSON_IETF decoding cases in Converter uncovered during
southbound gNMI Get/Subscribe probing (#557, #504):

- Treat empty, whitespace-only, and literal null JSON payloads as absent/no-op
  on containers, fields, and nested container members instead of failing with
  io.EOF, panicking on nil reflect.Type, or passing nil into
  sdcpb.ConvertJsonValueToTv (while preserving [null] on empty leaves and
  EmptyVal on child presence containers whose members are all null/state).
- Accept list keys present in both upd.Path and the JSON object when their
  normalized values agree (including bare and module-qualified JSON key names
  and identityref / leafref-to-identityref module qualifiers), while still
  erroring when values or explicit qualifiers disagree.

Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
@steiler
steiler requested a review from a team as a code owner November 27, 2026 09:54
…qualifiers

- Drop JSON null elements inside leaf-list arrays instead of emitting "<nil>".
- Treat empty, whitespace-only and null JSON on top-level leaf-list paths as
  no-op, matching container and field paths.
- Only reject identityref key qualifiers when the identity is present in the
  schema prefix maps; qualifiers on unknown identities are stripped as before.

Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.25743% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/utils/converter.go 74.25% 18 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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