Skip to content

_validators

root_validate_dict_keys(cls, object)

For each dictionary in object.values(), checks that that dictionary has only keys of type str.

Source code in fractal_server/app/schemas/_validators.py
78
79
80
81
82
83
84
85
86
def root_validate_dict_keys(cls, object: dict) -> dict:
    """
    For each dictionary in `object.values()`,
    checks that that dictionary has only keys of type str.
    """
    for dictionary in (v for v in object.values() if isinstance(v, dict)):
        if not all(isinstance(key, str) for key in dictionary.keys()):
            raise ValueError("Dictionary keys must be strings.")
    return object

val_absolute_path(attribute, accept_none=False)

Check that a string attribute is an absolute path

Source code in fractal_server/app/schemas/_validators.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def val_absolute_path(attribute: str, accept_none: bool = False):
    """
    Check that a string attribute is an absolute path
    """

    def val(cls, string: Optional[str]) -> Optional[str]:
        if string is None:
            if accept_none:
                return string
            else:
                raise ValueError(
                    f"String attribute '{attribute}' cannot be None"
                )
        s = string.strip()
        if not s:
            raise ValueError(f"String attribute '{attribute}' cannot be empty")
        if not os.path.isabs(s):
            raise ValueError(
                f"String attribute '{attribute}' must be an absolute path "
                f"(given '{s}')."
            )
        return s

    return val