What this thread does
Declare an explicit False default for HTML checkbox fields, then test omitted values, partial dumps and union selection before upgrading.
What changed
- On 2026-10-23 (checked 2026-10-28), FastAPI 0.162.0 (checked 2026-10-28) stopped synthesizing
Falsefor omittedboolandbool | Noneform fields; a default applies, or a required field is missing. This covers standalone parameters, models and model unions. Official release. - The same release excludes absent boolean model fields from
model_dump(exclude_unset=True)and stops treating their defaults as submitted fields during union selection; default factories andvalidate_defaultfollow normal rules. Official changelog.
The version policy identifies no supported/LTS release matrix; it advises pinning a working version and testing minor updates. The immediately preceding published release is 0.161.1; 0.161.0 adds combined form-model unions and 0.161.1 repairs nullable-union OpenAPI schemas. The release sequence has no intervening release before 0.162.0. No additional breaking entry appears in that interval (checked 2026-10-28).
How to migrate
1. Inventory Form parameters and form models with boolean fields. Classify each as a checkbox, a required API flag or an optional value; do not apply one default to all three. 2. For an unchecked-means-false checkbox, use the declaration copied from the Boolean Form Fields guide: subscribe: Annotated[bool, Form()] = False. Its alternative is subscribe: bool = Form(default=False). Import Annotated from typing and Form from fastapi. 3. Keep a field required if absence should be rejected. A nullable type alone does not choose an omission default; decide whether absence should use None and declare that default deliberately. 4. Update the project's existing FastAPI dependency constraint and lockfile to the release above. Keep the old lockfile available for comparison; do not combine this with unrelated dependency changes. 5. Audit consumers of model_dump(exclude_unset=True) and assertions about which union member is selected. Stop relying on an absent checkbox being recorded as submitted.
The problem
A form upgrade can silently change a defaulted boolean or remove a boolean key from a partial-update payload.
What breaks
| Declaration or consumer | Omitted field after the change |
|---|---|
Boolean defaulted to True | Uses True, rather than inferred False |
| Required boolean | Produces a missing-field error |
Partial dump with exclude_unset=True | Leaves an omitted boolean out |
| Union of form models | Defaulted booleans no longer increase submitted-field counts |
These are documented semantics, not results from running your application. The release does not prescribe one universal rendered error string.
Diagnostic: unchecked checkbox is omitted from the form
The form guide explains that browsers omit unchecked checkboxes; checked boxes normally send "on", which FastAPI accepts as True. Inspect the submitted form keys before changing validators.
What to test
Untested experiment. Run the same request cases against the old and new lockfiles: omit the field, send "on", and send an explicit false value. Assert both the parsed value and key presence in partial dumps. Exercise each relevant union branch and a field using a default factory or validate_default. Test the real browser form as well as a synthetic request.
Pitfalls
- A default of
Trueexpresses a different contract from an unchecked-means-false checkbox. - Absence is not the same thing as explicitly submitting false in a partial update.
- Do not copy a global missing-booleans validator into models also used outside forms.
Evidence
In discussion #13380, sneakers-the-rat describes the conflict between form checkboxes and a True model default; that historical discussion explains the use case, not proof of the new release's behavior. Maintainer tiangolo's merged PR #16605 is the implementation reference for the restoration. These are not two independent reports of successful upgrades.
Reports from users
- "Then it just doesn't work when the checkbox is unchecked." — @arminvburren, 2023-04-19, checked 2026-10-28. On FastAPI 0.79.0/Python 3.8, the author reports a working standalone
Form(False)but missing-value errors with a custom form-model decorator. This historical case motivates omission tests; it does not validate 0.162.0 or the example's model syntax.
A prompt to give your agent
Your training data predates this change. Read <https://github.com/fastapi/fastapi/releases/tag/0.162.0> and <https://fastapi.tiangolo.com/tutorial/request-forms/#boolean-form-fields> before editing; do not guess the old behavior. Inventory boolean form declarations, propose explicit omission defaults, then add request-level checks for values, exclude_unset key presence and union selection. Preserve required API flags. Report observed results separately from expected behavior.
Limits
No application migration, browser submission or union regression test has been run. Independent upgrade evidence is thin; the recommendation follows documented semantics and the maintainer change. Custom validators can impose additional behavior.
A previous supported line cannot be established from the official version policy. The bounded comparison is 0.161.1 → 0.162.0; upgrades from earlier versions need their own intervening notes, including the separate 0.160.0 model-extra change.
Started from a post by @fastapi, packaged by the editor. Original post