Skip to content

Validation Result DTO

validation_result_dto

Validation Result Data Transfer Object.

Defines the ValidationResultDTO, an immutable data transfer object that encapsulates validation results. Provides detailed validation outcomes with error messages and severity levels.

Classes:

Name Description
ValidationResultDTO

Immutable DTO containing validation results

Classes

ValidationResultDTO dataclass

ValidationResultDTO(is_valid: bool, errors: Optional[list[str]], warnings: Optional[list[str]], validated_items: int, message: str = '')

Immutable DTO for validation operation results.

Encapsulates validation outcomes including success status, error messages, warnings, and metadata about validated items.

Parameters:

Name Type Description Default
is_valid bool

Whether validation passed (no errors)

required
errors Optional[list[str]]

List of validation error messages (None if no errors)

required
warnings Optional[list[str]]

List of validation warnings (None if no warnings)

required
validated_items int

Number of items validated

required
message str

Summary message about validation result

""

Attributes:

Name Type Description
is_valid bool

Validation success status

errors Optional[list[str]]

Error messages

warnings Optional[list[str]]

Warning messages

validated_items int

Count of validated items

message str

Summary message

Notes
  • This DTO is immutable (frozen) to ensure data integrity
  • Errors prevent processing, warnings allow processing but flag issues
Functions
__post_init__
__post_init__() -> None

Validate DTO consistency.

Raises:

Type Description
ValueError

If is_valid=False but no errors, or validated_items is negative

Source code in src/application/dto/validation_result_dto.py
def __post_init__(self) -> None:
    """
    Validate DTO consistency.

    Raises
    ------
    ValueError
        If is_valid=False but no errors, or validated_items is negative
    """
    if not self.is_valid and (self.errors is None or len(self.errors) == 0):
        raise ValueError("is_valid=False requires error messages")

    if self.validated_items < 0:
        raise ValueError("validated_items cannot be negative")
has_errors
has_errors() -> bool

Check if validation has errors.

Returns:

Type Description
bool

True if errors exist

Source code in src/application/dto/validation_result_dto.py
def has_errors(self) -> bool:
    """
    Check if validation has errors.

    Returns
    -------
    bool
        True if errors exist
    """
    return self.errors is not None and len(self.errors) > 0
has_warnings
has_warnings() -> bool

Check if validation has warnings.

Returns:

Type Description
bool

True if warnings exist

Source code in src/application/dto/validation_result_dto.py
def has_warnings(self) -> bool:
    """
    Check if validation has warnings.

    Returns
    -------
    bool
        True if warnings exist
    """
    return self.warnings is not None and len(self.warnings) > 0
error_count
error_count() -> int

Get count of errors.

Returns:

Type Description
int

Number of errors

Source code in src/application/dto/validation_result_dto.py
def error_count(self) -> int:
    """
    Get count of errors.

    Returns
    -------
    int
        Number of errors
    """
    return len(self.errors) if self.errors else 0
warning_count
warning_count() -> int

Get count of warnings.

Returns:

Type Description
int

Number of warnings

Source code in src/application/dto/validation_result_dto.py
def warning_count(self) -> int:
    """
    Get count of warnings.

    Returns
    -------
    int
        Number of warnings
    """
    return len(self.warnings) if self.warnings else 0