Extra
This class provides a set of configuration options for controlling how extra attributes are handled during model initialization. It defines three distinct modes: allowing additional fields, ignoring them, or forbidding them entirely to ensure strict schema validation.
Attributes
| Attribute | Type | Description |
|---|---|---|
| allow | Literal['allow'] = 'allow' | Configuration setting that permits extra fields to be included in the model data during validation. |
| ignore | Literal['ignore'] = 'ignore' | Configuration setting that silently drops extra fields from the model data during validation. |
| forbid | Literal['forbid'] = 'forbid' | Configuration setting that raises a validation error if extra fields are present in the model data. |
Methods
allow()
def allow() - > str
Configures the model to permit and store extra fields provided during initialization that are not defined in the schema.
Returns
| Type | Description |
|---|---|
str | The literal string 'allow' used as a configuration flag. |
ignore()
def ignore() - > str
Configures the model to silently drop any extra fields provided during initialization that are not defined in the schema.
Returns
| Type | Description |
|---|---|
str | The literal string 'ignore' used as a configuration flag. |
forbid()
def forbid() - > str
Configures the model to raise a validation error if any extra fields are provided during initialization that are not defined in the schema.
Returns
| Type | Description |
|---|---|
str | The literal string 'forbid' used as a configuration flag. |