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

aliases & field configuration

5 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.alias_generators module

Pydantic provides an alias_generators module for generating field aliases.

Using aliases with SQLAlchemy to avoid reserved field names

When using Pydantic with SQLAlchemy, you can use Field aliases to avoid conflicts with reserved SQLAlchemy field names. For example, use Field(alias='metadata_') in a Pydantic model to map to a SQLAlchemy Column named 'metadata_', which gets stored as the database column 'metadata'. Aliases have priority over field names for field population during validation.

Field no longer accepts arbitrary keyword arguments for JSON schema

In Pydantic V2, Field no longer supports arbitrary keyword arguments to be added to JSON schema. Instead, pass extra data to JSON schema using the `json_schema_extra` keyword argument as a dictionary.

Field alias property returns None when no alias set

In Pydantic V1, the `alias` property returns the field's name when no alias is set. In Pydantic V2, this property returns `None` when no alias is set.

Field constraint properties removed or renamed

In Pydantic V2, the following Field properties have been removed or renamed: `const` (removed), `min_items` (renamed to `min_length`), `max_items` (renamed to `max_length`), `unique_items` (removed), `allow_mutation` (use `frozen` instead), `regex` (use `pattern` instead), `final` (use typing.Final type hint instead).

Give your agent this brain