Skip to content

fix(shadows): accept bare-string unit variants in externally-tagged parse_delta#129

Merged
KennethKnudsen97 merged 2 commits into
masterfrom
fix/parse-delta-bare-string-unit-variant
May 26, 2026
Merged

fix(shadows): accept bare-string unit variants in externally-tagged parse_delta#129
KennethKnudsen97 merged 2 commits into
masterfrom
fix/parse-delta-bare-string-unit-variant

Conversation

@KennethKnudsen97

Copy link
Copy Markdown
Contributor

Summary

For an externally-tagged enum with mixed unit + newtype variants (e.g. IpSettings { Dhcp, Static(...) }), the derived parse_delta only handled the object form ({"dhcp": ...}, {"static": {...}}). Serde itself serializes unit variants as a bare string ("dhcp"), and AWS echoes that shape back via shadow desired/delta — so devices loop on InvalidPayload whenever the cloud has the unit variant set.

This adds a bare-string fast-path before the FieldScanner call: trim ASCII whitespace, and if the value starts with ", match it against each unit variant's quoted name; fall through to the existing object-form scanner otherwise. Brings the macro's behaviour into line with what serde::Deserialize already accepts.

Found via factbird-mini #667.

Test plan

  • cargo test --lib --features std,shadows_kv_persist — 177 pass (incl. 4 new in src/shadows/shadow/tests.rs under 6.4 parse_delta accepts both bare-string and object forms)
  • Verified end-to-end against factbird-mini wifi shadow tests via local [patch] — the previously failing parse_known_network_with_bare_string_ip_settings regression now passes

…arse_delta

The derive emitted `parse_delta` for an externally-tagged enum with mixed
unit + newtype variants only handled the object form (`{"dhcp": ...}`,
`{"static": {...}}`). Serde, by contrast, serializes unit variants as a
bare string (`"dhcp"`), and AWS echoes that shape back via shadow
desired/delta — causing devices to loop on `InvalidPayload`.

Add a bare-string fast-path before the FieldScanner call: trim ASCII
whitespace, and if the value starts with `"`, match it against each
unit variant's quoted name; fall through to the existing object-form
scanner otherwise. Brings the macro's behaviour into line with what
`serde::Deserialize` already accepts.
Comment thread src/shadows/shadow/tests.rs

@MathiasKoch MathiasKoch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing.

Also, could we remove some of the unnecessary comments, and keep the comments to a strict "why we are doing this" on code that is not directly clear or is complex, as opposed to the current "what we are doing" style?

@KennethKnudsen97 KennethKnudsen97 merged commit 7d403f7 into master May 26, 2026
5 checks passed
@KennethKnudsen97 KennethKnudsen97 deleted the fix/parse-delta-bare-string-unit-variant branch May 26, 2026 09:39
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