Skip to content

Config model base

Base class for config models.

Automatically set up models based on the schema equivalents (providing means to override specific behaviour when necessary).

ConfigModelType = TypeVar('ConfigModelType', bound='ConfigModelBase') module-attribute

ConfigSchemaType = TypeVar('ConfigSchemaType', bound=ConfigSchemaBase) module-attribute

logger = logging.getLogger(__name__) module-attribute

ConfigModelBase

Bases: VersionedMixin, ConfigMetadataMixin, ModelWithSchema

__abstract__ = True class-attribute instance-attribute

id = mapped_column(primary_key=True) class-attribute instance-attribute

schema_class class-attribute

__admin_repr__(request)

__init_subclass__(**kwargs) classmethod

Set up the columns and relationships for the model based on the pydantic schema.

Schema determined by the schema_class class attribute.

__table_args__() classmethod

__tablename__()

Generate predictable table names based on the schema class name.

Note: Refactoring class names will require alembic migrations to rename the tables

field_column_overrides() classmethod

Override this method to define custom columns for fields in the schema.

Or to implement the fields that cannot be set up automatically.

Note: Set field to None to skip setting up a column for that field. Can then handle directly in the subclass.

Example:
@classmethod
def field_column_overrides(cls) -> dict[str, Column]:
    return {
        "some_field": Column(String(32), nullable=False)
        }

model_from_schema(schema) classmethod

Convert to a model.

to_schema(skip_validation=False)

Convert the SQLAlchemy model to the associated pydantic schema.

get_column(name, annotation)