Highlights
This patch release fixes env decoding of nested dictionary values, CliApp handling of AliasPath, nested secrets directory precedence and discriminated union defaults with nested_model_default_partial_update.
Behavior changes
- An explicit
secrets_dironNestedSecretsSettingsSourcenow takes precedence (#1093). Previously it was ignored when the wrappedSecretsSettingsSourceinherited a directory from model config, and an explicit empty list was masked too. The order is now: the wrapper'ssecrets_dirargument, then the wrapped source's directory, then model config. If you pass bothSettings(_secrets_dir=...)andNestedSecretsSettingsSource(..., secrets_dir=...), the wrapper's argument now wins.
Bug fixes
Env and dotenv sources
- Dictionary values typed as a union, such as
dict[str, list[str] | str]ordict[str, list[str] | None], now JSON-decode values set throughenv_nested_delimiter(#1089, #1097). Only JSON arrays and objects are decoded, so plain values like123,trueor"quoted"are kept as strings. Decoding followsenable_decodingand theNoDecode/ForceDecodeof the field that holds the dict, and type aliases andAnnotatedvalue types are resolved. - Nested dictionary values such as
dict[str, list[dict[str, str]]]are decoded at the right level again (#1109), soAPP_VALUES__X='[{"k":"v"}]'no longer reaches validation as a string.
CLI
CliApp.runnow rebuildsAliasPathinputs forBaseModeland pydantic dataclass commands (#1096). A supplied path used to be reduced to the field name, which failed validation.AliasChoicespriority is respected and unsupplied path defaults are left to the model.
Discriminated union defaults
- With
nested_model_default_partial_update=True, inner discriminated unions written asAnnotated[..., Field(discriminator='...')]are now detected (#1076). When the incoming tag selects another member, the default's fields are no longer merged into it. - A stdlib dataclass default on a discriminated union field no longer raises
NameErrorwhen another field of the dataclass has a string annotation naming a local class (#1077). Only the discriminator's own annotation is resolved now.
All changes (including dependency bumps and internal maintenance)
What's Changed
- build(deps): bump the python-packages group with 3 updates by @dependabot[bot] in #1056
- Detect nested Field discriminators in default partial updates by @digit50 in #1076
- Resolve only the discriminator annotation of stdlib dataclass defaults by @digit50 in #1077
- Decode nested dictionary values with complex union types by @chering14 in #1089
- Fix regressions from nested dict union value decoding (#1089) by @hramezani in #1097
- Fix explicit nested secrets directory precedence by @DivyamTalwar in #1093
- Fix CliApp reconstruction of AliasPath inputs by @DivyamTalwar in #1096
- Fix JSON decoding of nested dictionary environment values by @Hugohong258 in #1109
- Prepare release 2.16.2 by @hramezani in #1111
New Contributors
- @digit50 made their first contribution in #1076
- @chering14 made their first contribution in #1089
- @DivyamTalwar made their first contribution in #1093
- @Hugohong258 made their first contribution in #1109
Full Changelog: v2.16.1...v2.16.2