oxidecomputer / oxidecomputer/omicron
surprising behavior with serde / flatten / and deny_unknown_fields
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 572
- Forks
- 97
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 96
Description
We encountered this issue while resolving #440; this issue is to track debugging work and/or filing an issue with serde. We have a workaround (that may well be a fine long-term solution) so this issue is explicitly intended to defer that investigation. When resolving it, note the diffs in #440 to identify both places where updates may be needed.
Consider this struct:
pub struct VpcFirewallRuleUpdateParams {
#[serde(flatten)]
pub rules: HashMap<Name, VpcFirewallRuleUpdate>,
}
We can deserialize values into it just fine. However, if we add #[serde(deny_unknown_fields]) then it cannot be deserialized from valid values (other than, I believe, {}). I expect that this is a bug in serde. The next steps are to reproduce it with some simple test cases (e.g. one using String rather than Name), to look at the serde code for how flatten and deny_unknown_fields interact, and then to file an issue with serde).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the diffs in #440 to identify both places that may need updates, then reproduce the behavior with small serde cases, including String instead of Name. Inspect how flatten and deny_unknown_fields interact in serde, and consider filing a serde issue; done means the behavior is reproduced and either an upstream issue is filed or the workaround is confirmed as sufficient.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100