Breaking Changes
Code Generation Changes
- A pydantic dataclass aliases a later class that an inherited field name hides - A pydantic_v2.dataclass failed to import when a base has a required Field() (such as Place: str = Field(..., min_length=1) with --field-constraints) named like a class the module defines after the subclass or like the subclass itself, and an annotation of the subclass names that class (where: Place | None, Optional[Place], list[Place], also through a class between and in a package module). The failure is on Pydantic 2.8.2 to 2.11.7 for a later class and on 2.8.2 for the class itself: those releases copy the base's FieldInfo into the subclass and evaluate its annotations there. A dataclass with slots for a target Python of 3.10 failed the same way on Python 3.10, where the subclass holds a slot of the inherited field. The annotation now names _aliased, which the module binds after the class (Place_aliased = Place), as it already did for an earlier class; Pydantic resolves it at the first use of the subclass. Class names, field names and order, bases, required-ness, init parameters and parsed values are the same; a target of 2.12 and later, the constr form and a later class that only the inherited defaults of Pydantic 2.0 bind keep their text. Nothing restores the old text: it failed to import on the Pydantic releases above. (#7690)
- A module that binds the name another module's alias quotes to another class names the class the schema gives - In a package output, a module that named an alias of another module written Name: TypeAlias = "Event" while it binds Event to another class, a class of its own or an import of another module's Event (--use-exact-imports), resolved the string to that class (also where the binding is a module alias of that name, and in an alias body of the alias's own module that names such an alias): the hint read the wrong model and a valid payload lost the schema's fields (name and parent of a.Event read as b.Event). This happened for dataclasses.dataclass, typing.TypedDict and msgspec.Struct with a target Python of 3.10 or 3.11, and for pydantic_v2.dataclass with --target-pydantic-version 2. The hint now writes the class the schema names (a.Event, or Event_1 where the import of a.Event takes another name), so payloads keep their fields. A module that imports the target itself under the quoted name keeps the alias. Where a module under --use-exact-imports imports only some of the names an alias value quotes (from .a import Event for Union["Event", "Other"]), the alias failed with NameError for the others; the hint now writes the value and imports the names it lacks. Class names, field names and order, bases and required-ness are the same. (#7680, #7678)
- Schema validators count the contains matches of object subschemas and local references - Experimental:
cli-option.generate-schema-validators. With--generate-schema-validators(or--schema-validator-type pydantic-v2), acontainsschema that holdsrequired,properties,additionalProperties,minProperties,maxProperties,allOfor a$refwithin the same document, also in its subschemas and in the schemas it references (a recursive reference included), now gets the count check ofminContainsandmaxContains:[{"kind": "target"}, {"kind": "target"}]is now rejected forcontains: {$ref: "#/$defs/Target"}, maxContains: 1whereTargetrequireskindwithconst: "target", as JSON Schema rejects it. Object keywords pass a value that is no object, as JSON Schema reads them. The keywords beside a$refcount where the draft applies them (2019-09 on) and are ignored before. A contains with any other keyword anywhere inside (anyOf,oneOf,not,patternProperties,format, ...), a$refto another document or inside a subschema with its own$id, and, under--allow-population-by-field-name, one that reads property names still gets no count check. An item that is not a JSON value, such as a model instance passed tomodel_validate, may match: it no longer counts as a non-match, so[Target(kind="a")]is accepted forcontains: {type: object}as its JSON value is. The rows of__json_schema_contains__gain the matchers of the referenced schemas, and the shared base gains the helpers that read them. Class names, fields, types and bases are unchanged, and without the option nothing changes. (#7695, #7692, #7693) - Schema validators check required groups in if/then/else branches and at referenced sites - Experimental:
cli-option.generate-schema-validators,cli-option.schema-validator-type. With--generate-schema-validators(or--schema-validator-type pydantic-v2), the shared base checks theoneOf,anyOfandnotrequired-property groups and therequiredof an if/then/else branch with one evaluator written in Python beside the template part of the base. The rows of the models are unchanged, except that two if/then/else whose conditions differ only as a boolean and a number, such asconst: trueandconst: 1, now write a rule each: 0.106.0 merged them into one, sinceTrue == 1in Python, and accepted a payload such as{"kind": 1}that theconst: 1branch rejects. A payload that breaks two rules may report another of them first. An if condition reads a property by the first input name present, as the numeric bounds layer does. TheoneOf,anyOf,not(anotof ananyOfof required groups too) andrequiredgroup rules that thethenandelseof an if/then/else put beside their ownrequiredare checked for the branch the condition selects. A property, array item or map value typed as a class by a$refwhose siblings the draft applies, or by an allOf with one$refand no model of its own, is checked for the required names,oneOf,anyOf,notgroups and if/then/else branches beside the$refthat the referenced schema does not hold itself; the names are the input names of the referenced class once it is generated, else the names of the schema, and with--allow-population-by-field-name,--alias-generatoror--use-serialization-aliassuch a site gets no check. With a customschema_runtime_validation_helpers.jinja2the output is what 0.106.0 wrote: the group checks of the branches, of the classes referenced and of anotof ananyOfare not generated, and a warning says so. Class names, fields, types and bases are unchanged, and without the option nothing changes. (#7725, #7700, #7701, #7702) - An object x-python-type of a mapping class is a root of that mapping, not an empty class - A definition or document of type object with no properties whose x-python-type is a mapping class the schema type fits (dict[str, int], typing.Dict, Mapping, MutableMapping, a bare dict, or such an object in an allOf) was an empty class (class Counts(BaseModel): pass) that dropped every value: Holder.model_validate({"counts": {"a": 1}}) gave counts {}. It is a root of that mapping now (class Counts(RootModel[dict[str, int]])), as 0.106.0 roots an object x-python-type of a class that does not fit (#7643); --use-root-model-type-alias keeps it a class, --use-type-alias, pydantic_v2.dataclass, dataclasses.dataclass, typing.TypedDict and msgspec.Struct write a type alias of the mapping, and --collapse-root-models inlines it. The values now stay ({"a": 1}), and a value the mapping refuses ({"a": "x"} for int) is rejected where the empty class dropped it. A class that forbids undeclared keys (additionalProperties: false, --extra-fields forbid), over its own mapping or over a $ref base that holds one (that base stays a class too), or keeps them (additionalProperties: true, --extra-fields allow) is written as before, and so are a bare TypedDict and an Optional[...] text without --use-x-python-type-as-written; under --reuse-model (and so under the practical presets, which turn it on) every such class is written as before, since the class that equal classes reuse is chosen after the roots are decided and a root would move their bases; --extra-fields ignore, which comes before additionalProperties: false, roots such a closed object, so it keeps the keys the schema forbids where the class dropped them. The root takes its value type from the x-python-type, while the same object written inline in a field, or with additionalProperties, minProperties, propertyNames or patternProperties, takes the schema's value type (dict[str, Any] where the schema leaves the values open), so {"a": "x"}, valid for the schema, is rejected only in the root form. Class names, field names, references and model order are the same; under --collapse-root-models and the dated presets without --reuse-model the former class name is inlined into its holders, and under --strip-default-none together with --use-default-factory-for-optional-nested-models a field that holds such a root is required (no default factory), as for the roots of 0.105.0 (#7581). Decided by the owner on 2026-11-30 under the #7581 exception. (#7686, #7667)
API/CLI Changes
- ContainsRule holds the matchers of the schemas its matcher references - ContainsRule gains refs, the matchers of the schemas that the ('$ref', index) pairs of its matcher name, empty by default. Nothing is removed or changed. (#7695, #7692)
- resolve_preset_config_updates accepts any set of explicit fields - The explicit_fields parameter of resolve_preset_config_updates is typed AbstractSet[str] instead of set[str]; the function only reads it, so a frozenset is accepted too. Callers passing a set are unaffected. (#7694)
- Store operation that records the alias values a field's hint writes - GenerationStore.record_hint_alias_values (with GraphBuilder.record_hint_alias_values) records, on a field, the values of the evaluated type aliases of other modules that its hint writes in their place. Nothing is removed or changed. (#7675)
- SchemaRuntimeValidation holds the group rules of if/then/else branches - SchemaRuntimeValidation gains required_group_paths, a list of RequiredGroupsPathRule, empty by default; ConditionalGroupRules, RequiredGroupsPathRule, GroupRules and GroupKeyword are new names of model.runtime_validation. Nothing is removed or changed. (#7725)
Changes That Need No Action
- Generated clients name a model where its alias's value is a quoted name - Experimental:
cli-option.generate-client. With--generate-clientand models whose type alias is writtenName: TypeAlias = "Event"(dataclasses.dataclass, typing.TypedDict and msgspec.Struct with a target Python of 3.11; alsolist["Tree"]and aliases of such aliases), the client named the alias (body: a.EventRef,DataclassCodec[a.EventRef],ListEventsResponse: TypeAlias = models.EventsGetResponse). At runtime the alias is the string"Event", which no client module binds:typing.get_type_hintsraisedNameErroron the resource methods, the pagination, stream and webhook helpers, the AsyncAPI channel helpers and the codec module, a body field argument (--client-body-arguments both) made the client fail at import, msgspec codecs raisedTypeErroron every call, and dataclass codecs left a nestedparenta dict. The client now writes the alias's value with the names unquoted (body: a.Event,list[a.Tree],a.Tree | None,ListEventsResponse: TypeAlias = list[a.Event]), as the models of another module do, and decodes nested models. Aliases written unquoted (PetRef: TypeAlias = Pet), a cycle of quoted aliases, the Pydantic backends and the models are unchanged. (#7696, #7674) - A module names another module's alias whose value quotes a name by that value - In a package output, a module that named an alias of another module written Name: TypeAlias = "Event" (also list["Event"] or dict[str, "Node"], and aliases of such aliases) failed at the first use of its hints: Python and Pydantic resolve the string in the module that names the alias, where no Event is, so typing.get_type_hints and msgspec raised NameError and a pydantic_v2.dataclass for --target-pydantic-version 2 was not fully defined. This happened for dataclasses.dataclass, typing.TypedDict and msgspec.Struct with a target Python of 3.10 or 3.11, and for pydantic_v2.dataclass with --target-pydantic-version 2. The hint now writes the alias's value with the names unquoted (a.Event, list[a.Event], Optional[a.Event]), also in an alias of the alias (Again: TypeAlias = a.Event) and through a third module, and imports the classes it names; the module keeps every name it imported. Only modules that failed at first use change: class names, field names and order, bases, required-ness and parsed values are the same, and a module that imports the quoted class itself under that name, where the string resolved to it, is unchanged (a module that binds the name to another class: quoted-alias-name-bound-to-another-class). (#7675, #7652, #7660, #7678)
- Generated servers take
application/json; charset=utf-8as a response's default media type - Experimental:cli-option.generate-server. With--generate-server fastapi, a response that lists another media type, such astext/plainorapplication/problem+json, beforeapplication/json; charset=utf-8took the first one as its default media type, so a service that returned the JSON model's value answered500. The default media type is now the declarationapplication/jsonfalls under (one without parameters first, then the first with parameters), else the first other JSON type, else the first declared one. The route answers with the declaredContent-Type, for exampleapplication/json; charset=utf-8. The contract, the services protocol and its return types name the JSON media's model instead of the text one, and a response whose JSON type takesnullacceptsNone. A service that relied on returning the value of the first media's type now goes through the JSON model. Responses that declareapplication/jsonwithout parameters, a+jsontype without a parameterizedapplication/json, or a single media type are unchanged. (#7723)
What's Changed
- Stamp the upgrade guide entries of 0.106.0 by @koxudaxi in #7671
- Read a PassSpec name and when given by keyword in the gate check by @koxudaxi in #7672
- Sign a hint's quoted name that its module cannot resolve as an error by @koxudaxi in #7676
- Write another module's quoted alias value in the hints naming it by @koxudaxi in #7675
- Drop the cross-module alias record's payload cells that match no cell by @koxudaxi in #7679
- Move heki to 0.14.0 and keep deep warnings out of its baseline by @koxudaxi in #7677
- Route the model name path key split through the reference home by @koxudaxi in #7682
- Add the cross-module alias inputs that import names by @koxudaxi in #7681
- Approve the heki baseline rise of the hash-split contract by @koxudaxi in #7684
- Check hash splits with a heki contract instead of a source rule by @koxudaxi in #7683
- Check hash splits with the heki contract instead of the source rule by @koxudaxi in #7685
- Write a quoted alias value where the module binds the name elsewhere by @koxudaxi in #7680
- Annotate the parameters heki proves read-only with read-only types by @koxudaxi in #7688
- Alias a later class that an inherited dataclass field name hides by @koxudaxi in #7690
- Move heki to 0.14.1 and check pass gates with a heki boundary by @koxudaxi in #7691
- Accept any set for the explicit fields of resolve_preset_config_updates by @koxudaxi in #7694
- Approve the dynamic import of the quoted-alias client scenario by @koxudaxi in #7697
- Write an object x-python-type of a mapping class as its root by @koxudaxi in #7686
- Write a quoted alias's value in client annotations by @koxudaxi in #7696
- List the callers of each decision home by module and layer by @koxudaxi in #7699
- Count contains matches of object subschemas and local references by @koxudaxi in #7695
- Move heki to 0.14.2 by @koxudaxi in #7705
- Read heki baselines of version 5 in the ratchet by @koxudaxi in #7722
- Write the heki baseline in the version 5 format by @koxudaxi in #7724
- Pick the JSON media of a response by its essence by @koxudaxi in #7723
- Count ty ignores under the rule names ty 1.0 gives them by @koxudaxi in #7726
- Enforce schema validator group rules in branches and sites by @koxudaxi in #7725
- Declare that schema validators keep true and 1 conditions apart by @koxudaxi in #7730
Full Changelog: 0.106.0...0.107.0