Skip to main content

AttributeTemplateValidator

Transient validator for a raw attribute definition supplied via the builder API.

Usage

Source

AttributeTemplateValidator()

This model is used only during builder operations to validate and coerce the dict-style attribute definitions that users pass to add_properties() and similar methods before they are written to the database. It is not persisted.

Example input accepted by add_properties()::

{"name": "volume", "type": "float", "default": 10.0, "unit": "uL",
 "metadata": {"min": 0, "max": 20.0}}

Attributes: name: Attribute name (may contain spaces). type: One of the TypeName literals. unit: Physical unit string. Defaults to an empty string. default: Default value, coerced to the Python type for type by coerce_default(). metadata: Optional validation hints (min, max, choices).

Methods

Name Description
coerce_default() Coerce default to the Python type declared by type.
enforce_enum_choices() Ensure enum attributes declare choices and that default is valid.

coerce_default()

Coerce default to the Python type declared by type.

Usage

Source

coerce_default(v, info)

Preserves null; otherwise applies the shared Python value converter.

Raises

ValueError

If type is not yet resolved, is unsupported, or if v cannot be coerced.


enforce_enum_choices()

Ensure enum attributes declare choices and that default is valid.

Usage

Source

enforce_enum_choices()

Raises

ValueError

If type is "enum" and metadata.choices is absent, empty, or does not contain the declared default.