new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Pydantic · all subjects

configdict & configuration

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

pydantic.config module contents

The pydantic.config module exports the following public members: ConfigDict, with_config, ExtraValues, and BaseConfig.

from_attributes ConfigDict option enables ORM mode

Set model_config = ConfigDict(from_attributes=True) to enable ORM mode in Pydantic v2. This allows Pydantic models to populate fields from ORM object attributes using model_validate(), enabling seamless conversion between ORM models (like SQLAlchemy) and Pydantic models.

from_attributes config option replaces orm_mode

In Pydantic V2, the config option `from_attributes` replaces the V1 `orm_mode` option. Setting `from_attributes=True` enables validation from ORM-like objects.

Pydantic dataclasses no longer support extra='allow'

In Pydantic V2, dataclasses no longer support `extra='allow'` where extra fields passed to the initializer would be stored as attributes. The setting `extra='ignore'` is still supported for ignoring unexpected fields during parsing.

Vanilla dataclass config no longer inherits from parent

In Pydantic V2, when using a vanilla dataclass as a field, the parent type's config is no longer used as the config for the dataclass. Use the `config` parameter on the @dataclass decorator to override config like you would with `model_config` on a BaseModel.

model_config class attribute replaces Config class

In Pydantic V2, specify model config using a class attribute `model_config` set to a dict with config key/value pairs. The V1 pattern of creating a class called `Config` in the namespace of a BaseModel subclass is deprecated.

model_config inheritance and merging

In Pydantic V2, the `model_config` attribute is inherited when subclassing a model. When inheriting from multiple BaseModel subclasses, non-default settings from both models are merged, with settings from the second model overriding those from the first.

ConfigDict removed settings list

In Pydantic V2, the following config settings have been removed: `allow_mutation`, `error_msg_templates`, `fields`, `getter_dict`, `smart_union`, `underscore_attrs_are_private`, `json_loads`, `json_dumps`, `copy_on_model_validation`, `post_init_call`.

ConfigDict renamed settings

In Pydantic V2, the following config settings have been renamed: `allow_population_by_field_name` → `populate_by_name` (or `validate_by_name` starting in v2.11), `anystr_lower` → `str_to_lower`, `anystr_strip_whitespace` → `str_strip_whitespace`, `anystr_upper` → `str_to_upper`, `keep_untouched` → `ignored_types`, `max_anystr_length` → `str_max_length`, `min_anystr_length` → `str_min_length`, `orm_mode` → `from_attributes`, `schema_extra` → `json_schema_extra`, `validate_all` → `validate_default`.

Give your agent this brain