Validation
psengine.helpers.validation
¶
validate_list
¶
validate_list(
model_cls: type[T],
items: Iterable[Any],
id_path: str | None = None,
log: Logger | None = None,
) -> list[T]
Validate a list of dicts against model_cls.
Uses pydantic's TypeAdapter so a single validation pass collects all per-item errors with an
index in their loc.
Before re-raising, each failing item is (a) logged individually as a warning and (b) on
Python 3.11+ attached to the exception via add_note, so the entity identifier shows up in
the traceback too. On Python 3.10 the note step is skipped since BaseException.add_note
is not available.
If id_path is provided, a human-readable identifier is extracted from the raw dict
(e.g. entity.name); otherwise only the index is reported.
| PARAMETER | DESCRIPTION |
|---|---|
model_cls
|
Pydantic model each item should validate against.
TYPE:
|
items
|
Raw items to validate, typically dicts from an API response.
TYPE:
|
id_path
|
Dotted path into each raw item used to build a friendly identifier for log lines and exception notes, e.g.
TYPE:
|
log
|
Logger for the warnings. Defaults to this module's logger.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValidationError
|
If any item fails validation. Unchanged
from |
| RETURNS | DESCRIPTION |
|---|---|
list[T]
|
The list of validated |