Fields
Fields are the columns of a table. Every field has an id, a data type, and
optional Validator instances. Three concrete
field types differ in where the value comes from:
DataField— imported data, with an optional default value.CalculatedField— value computed by aFormula.ComboField— carries both a formula and a stored value; thecalculate_in_optimiserflag decides whether the optimiser evaluates the formula (True) or reads the stored value (False). The opposite mode is used outside optimisation, e.g. when the field is rendered in the UI.
Field hierarchy: Field base + the three concrete field types
(DataField, CalculatedField, ComboField).
A field is a column on a Table. Each field carries an id,
a data type, and an optional set of Validator
instances. Concrete field types differ in where the value comes from — imported
data, a formula, or a hybrid that switches between the two.
- class Field(id, table, data_type)[source]
Abstract base for a column on a
Table.Use the concrete subclasses
DataField,CalculatedField, andComboFieldrather than constructingFielddirectly. Every field has anid, an owningtable, and adata_type; optionally anorder_index, adescription, and zero or moreValidatorinstances (at most one perSeverity).- table_id
The owning table’s id.
- data_type
The
BaseDataTypeof this field.
- property tracking_group: str | None
Tracking-group identifier, or
Nonewhen change tracking is disabled.
- property tracking_id: str
ID of the matching tracking field, or empty string when this field is not tracked.
- set_order_index(idx)[source]
Set the field’s position within its table (lower values come first).
- Return type:
- set_tracking_group(group)[source]
Enable change tracking by assigning this field to a tracking group.
When set,
build()generates a sibling<group>_TRACKING_<id>field; references to other tracked fields within the same group are rewritten to their tracking ids.- Return type:
- add_validator(validator)[source]
Attach a
Validatorto this field.Each field may carry at most one validator per
Severity.- Raises:
ValueError – If a validator with the same severity is already attached.
- Return type:
- get_validation_fields(severity=None)[source]
Return the synthetic validation fields generated for this field’s validators.
- Parameters:
severity (
Severity|None) – When given, return only the validation fields for that severity. WhenNone, return oneValidationFieldsContainerper attached validator, sorted by ascending severity rank.- Return type:
list[ValidationFieldsContainer] |ValidationFieldsContainer|None- Returns:
A single
ValidationFieldsContainer, a list of them, orNoneif no validator matches.
- get_combined_message_field()[source]
Return a single calculated field combining all per-severity messages.
The combined field is a STRING_ARRAY ordered from highest to lowest severity (CRITICAL → ERROR → WARNING → INFO); blank messages are excluded. The field is registered on the table as
{id}__message__combinedon first call and cached for subsequent calls.
- class CalculatedField(id, table, formula)[source]
A field whose value is computed by a
Formula.The field’s data type is taken from the formula. Calculated fields are read-only — their value is recomputed whenever inputs change.
- formula
The formula evaluated to produce this field’s value.
- class DataField(id, table, data_type)[source]
A field populated from imported data or an optional default value.
- import_format: str | None
Import format hint (e.g. a date pattern) applied when parsing input rows.
- set_default_value(value)[source]
Set the default value used when no imported value is present.
- Return type:
- set_import_format(fmt)[source]
Set the import format hint applied when parsing this field on import.
- Return type:
- class ComboField(id, table, formula, calculate_in_optimiser)[source]
A field that switches between data and calculated behaviour.
Combo fields carry a
Formulaand an underlying stored value. Thecalculate_in_optimiserflag chooses which one the optimiser sees:calculate_in_optimiser=True: the optimiser evaluates the formula (treating the field as aCalculatedField), while outside optimisation the stored data value is used.calculate_in_optimiser=False: the optimiser uses the stored data value (treating the field as aDataField), while outside optimisation — for example when the field is rendered in the UI — the formula is evaluated (treating the field as aCalculatedField).
- formula
Formula evaluated when the field is treated as calculated.
- calculate_in_optimiser
Selects whether the optimiser evaluates the formula or reads the stored value. See the class docstring for the full behaviour.
- set_default_value(value)[source]
Set the default value used when no imported value is present.
- Return type: