30 lines
etl/row_validator.py
Validates required fields in a parsed transaction row.
# Row validation for the transaction ingestion pipeline.
from typing import Tuple
 
REQUIRED_FIELDS: Tuple[str, ...] = (
    "transaction_id",
    "user_id",
    "amount",
    "currency",
)
 
 
# Parameters: row — dict of parsed transaction fields keyed by field name.
# Returns: True if every required field is present with a non-falsy value, else False.
def validate_row(row: dict) -> bool:
    """Return True if row contains all required fields with non-None values.
 
    Parameters
    ----------
    row : dict
        Parsed transaction row with fields already cast to their target types.
 
    Returns
    -------
    bool
        True when every required field is present and carries a value.
    """
    for field in REQUIRED_FIELDS:
        if not row.get(field):
            return False
    return True