Skip to content

Config schema base

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

logger = logging.getLogger(__name__) module-attribute

ConfigMetadataSchema

Bases: SchemaBase

copied_from_name = Field(default=None, max_length=100) class-attribute instance-attribute

copied_from_type = None class-attribute instance-attribute

name = Field(default='Default', max_length=100) class-attribute instance-attribute

type = ConfigType.NOT_SET class-attribute instance-attribute

user_id = Field(exclude=False, description='User ID is only relevant when type is USER, and is determined by the users login. Should not be exposed to the client, call .set_meta(user_id=None, nested=True) to remove.', default=None) class-attribute instance-attribute

equal_to(other, keys_to_recursively_remove=None, exclude_id=False, include_version=False, exclude_copied_from=False)

For more complex comparisons where schema1 == schema2 is not sufficient.

E.g. Trying to compare all values without metadatas or ids.

new_copy(new_name, new_type, new_user_id)

set(name=None, type_=None, user_id=None, copied_from_name=None, copied_from_type=None, as_new=False)

validate_copied_combination()

validate_copied_from_type(v)

validate_name(v)

validate_type_user_id_combination(info)

ConfigSchemaBase

Bases: DatabaseSchemaMixin, SchemaBase, ABC

Base class for all configs schemas.

meta = ConfigMetadataSchema() class-attribute instance-attribute

model_config = ConfigDict(extra='forbid') class-attribute instance-attribute

new_instance_on_change = True class-attribute

Should a whole new instance be created in the database for any change (version increment) vs changing in place.

determine_version_increment(other)

equal_to(other, keys_to_remove_recursively=None, exclude_metas=False, exclude_id=True, include_version=False)

For more complex comparisons where schema1 == schema2 is not sufficient.

E.g. Trying to compare all values without metadatas or ids.

increment_version()

mark_deleted(nested=False)

new_copy(new_name, new_type=None, new_user_id=None, nested=False)

Create a copy of the schema (resetting version and id).

PARAMETER DESCRIPTION
new_name

New name for the schema

TYPE: str

new_type

New type for the schema

TYPE: ConfigType | None DEFAULT: None

new_user_id

New user_id for the schema

TYPE: int | None DEFAULT: None

nested

Whether to also create new copies of all sub-schemas

TYPE: bool DEFAULT: False

Note: Replacing all nested schemas ensures that any future updates are not ambiguous as to which schema they are intended to update. Useful when sub-schemas are ONLY considered part of the parent schema.

reset_ids(nested=False)

Set all ids to None.

Remove all persistence ids.

reset_incremented_for_testing()

reset_version(nested)

Set all versions to None.

set_ids_from_model(model)

Set the ID and version from a model instance.

Used when creating a new schema from a model instance. Only used in repository/uow methods.

set_initial_version()

set_meta(name=None, type_=None, user_id=None, copied_from_name=None, copied_from_type=None, meta=None, nested=False, as_new=False, condition=None)

Update the metadata on the schema (and all nested schemas if nested is True).


name: Optional new name to set
type_: Optional new type to set
user_id: Optional new user_id to set
copied_from_name: Optional new copied_from_name to set
copied_from_type: Optional new copied_from_type to set
version: Optional new version to set
meta: Optional new full meta to set
nested: Whether to apply update to nested schemas
as_new: If true, resets version and id (and automatically copies from current)
condition: Callable to determine whether to apply the update to the schema (receives the schema as arg)

sub_schemas()

tablename() classmethod

ConfigType

Bases: StrEnum

GLOBAL = 'global' class-attribute instance-attribute

IMMUTABLE = 'immutable' class-attribute instance-attribute

NOT_SET = 'not_set' class-attribute instance-attribute

USER = 'user' class-attribute instance-attribute

InvalidCopyError

Bases: BackendError