Skip to content

artifact_user_validator

Validator for the user fields of an artifact.

ArtifactUserValidator

Bases: CrossValidator

Implementation of CrossValidator to validate an artifact against the user store.

Source code in mlte/store/validators/cross_validators/artifact_user_validator.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class ArtifactUserValidator(CrossValidator):
    """Implementation of CrossValidator to validate an artifact against the user store."""

    def __init__(
        self,
        user_store: UserStore,
    ):
        """
        Initialize a ArtifactUserValidator instance.
        :param user_store: User store to use for validation.
        """
        self.user_store = user_store

    def validate(self, new_artifact: ArtifactModel) -> None:
        if new_artifact.header.creator:
            with ManagedUserSession(self.user_store.session()) as session:
                try:
                    session.user_mapper.read(new_artifact.header.creator)
                except ErrorNotFound:
                    raise RuntimeError(
                        f"Artifact creator validation failure. User: {new_artifact.header.creator} not found. For artifact {new_artifact.header.identifier}."
                    )

__init__(user_store)

Initialize a ArtifactUserValidator instance.

Parameters:

Name Type Description Default
user_store UserStore

User store to use for validation.

required
Source code in mlte/store/validators/cross_validators/artifact_user_validator.py
13
14
15
16
17
18
19
20
21
def __init__(
    self,
    user_store: UserStore,
):
    """
    Initialize a ArtifactUserValidator instance.
    :param user_store: User store to use for validation.
    """
    self.user_store = user_store