Overview
| Artifact ID: | 8b6b8ac5ecbbcaefacaa4fb51666810f56138197721ef3240e66c267d5a2e0f7 |
|---|---|
| Ticket: | 9e71cc1513f505341c36aae5e97fb6cb3e9669c7
validate default= is published in op docs but never applied to a JSON body |
| User & Date: | zeitgeist on 2026-09-13 15:31:47 |
Changes
- Untracked field cmimetype: "text/x-markdown"
- comment changed to:
Found while adding a member over the API: `team.member` declares `listed` with `default=1`, the op documentation says so, and a JSON request omitting the field produced an UNLISTED member. The caller was told the opposite of what happened. The cause is wider than that op. `applyDefault` is reached only from `DecodeValues`, which the router uses for GET query strings and POST forms. A JSON body goes straight through `json.NewDecoder` into the struct in `decodeIn` and never sees a validate tag. `ops.Descriptor` publishes the default regardless, so every op with `default=` on any field documents a behaviour that does not happen for JSON callers. That is 185 ops sharing one codec. A second, narrower bug in the same tag was fixed alongside it: `applyDefault` had cases for int, uint and float and none for bool, so `default=1` on a bool was dead on EVERY path, not just JSON. Why this is worth its own change rather than a footnote: a default that applies on one transport and not another is the kind of difference nobody checks for, because the documentation is the same in both. The web form never showed it because the form handler sets the field explicitly on every submit. Options, roughly in order of how much they cost: 1. Stop publishing a default that cannot be honoured — narrowest, and it makes the documentation true, but it leaves the tag misleading to whoever writes the next op. 2. Apply defaults on the JSON path by decoding into a map first to learn which keys were absent, then into the struct. Correct and uniform, and it touches the codec every op shares, so it wants doing deliberately rather than as a side effect. 3. Make absence explicit in the op, as team.member now does: a pointer field, where nil means the caller did not mention it. Correct per-op, no codec change, but it has to be remembered every time — the same shape of hazard as a rule that lives at 185 call sites instead of one. The immediate case is fixed by 3 on branch absent-means-keep, which also gave applyDefault its Bool case and taught setField and fieldSchema about pointers. This ticket is for the codec question that fix deliberately did not answer. Related, and the reason the pointer mattered more than the default: team.member is an upsert, so a plain bool could not tell "set this false" from "I did not mention it". A caller changing an owner's caps without naming `owner` demoted them and got ok back.
- severity changed to: "moderate"
- status changed to: "Open"
- title changed to:
validate default= is published in op docs but never applied to a JSON body
- type changed to: "bug"