Skip to content

catalog_tag_validator

Validator for the tags field of a catalog entry.

CatalogTagValidator

Bases: CrossValidator

Implementation of CrossValidator to validate a catalog entries tags against custom list store.

Source code in mlte/store/validators/cross_validators/catalog_tag_validator.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class CatalogTagValidator(CrossValidator):
    """Implementation of CrossValidator to validate a catalog entries tags against custom list store."""

    def __init__(
        self,
        custom_list_store: CustomListStore,
    ):
        """
        Initialize a CatalogTagValidator instance.
        :param custom_list_store: Custom list store store to use for validation.
        """
        self.custom_list_store = custom_list_store

    def validate(self, new_entry: CatalogEntry) -> None:
        with ManagedCustomListSession(
            self.custom_list_store.session()
        ) as session:
            for tag in new_entry.tags:
                try:
                    session.custom_list_entry_mapper.read(
                        tag,
                        CustomListName.TAGS,
                    )
                except ErrorNotFound:
                    raise RuntimeError(
                        f"Catalog entry tag validation failure. Tag: {tag} not found. For catalog entry {new_entry.header.identifier}."
                    )

__init__(custom_list_store)

Initialize a CatalogTagValidator instance.

Parameters:

Name Type Description Default
custom_list_store CustomListStore

Custom list store store to use for validation.

required
Source code in mlte/store/validators/cross_validators/catalog_tag_validator.py
14
15
16
17
18
19
20
21
22
def __init__(
    self,
    custom_list_store: CustomListStore,
):
    """
    Initialize a CatalogTagValidator instance.
    :param custom_list_store: Custom list store store to use for validation.
    """
    self.custom_list_store = custom_list_store