What's Changed
- Improve type resolution for inherited fields in allOf with complex schemas by @koxudaxi in #2614
- Fix circular imports in generated multi-module packages by @koxudaxi in #2613
- Wrap RootModel default values with type constructors by @koxudaxi in #2615
- Strict types now enforce field constraints by @koxudaxi in #2617
- Use default_factory for $ref with default values when using --use-annotated by @koxudaxi in #2618
Breaking Changes
Custom Template Update Required
If you use custom Jinja2 templates, you may need to update them to handle default_factory correctly with --use-annotated.
A new property field.has_default_factory_in_field has been added. Templates should check this property to avoid generating duplicate
default assignments when Field(default_factory=...) is used.
Example change in templates:
{# Before #}
{%- if not (field.required or ...) %} = {{ field.represented_default }}{% endif %}
{# After #}
{%- if not field.has_default_factory_in_field and not (field.required or ...) %} = {{ field.represented_default }}{% endif %}Affected built-in templates:
- pydantic/BaseModel.jinja2
- pydantic/BaseModel_root.jinja2
- pydantic_v2/BaseModel.jinja2
- pydantic_v2/RootModel.jinja2
Full Changelog: 0.41.0...0.42.0